我有一个名为gui的按钮" F4,"现在,当我点击该按钮时,我希望它模拟键盘上的F4按钮。
有可能吗?
这是按钮:
Gui, Add, Button, x20 y260 w50 h20, F4
答案 0 :(得分:0)
取自 this forum post :
Gui, +LastFound +AlwaysOnTop -Caption +E0x08000000
Gui, Font, s22, Arial
Gui, Add, Button, x0 y0 w100 h50 gButton, F4
Gui, Show, x0 y0 w100 h50 NoActivate
; Define a hotkey to show/hide the Gui:
F1::
toggle := !toggle
If (toggle)
Gui, Cancel
else
Gui, Show, NoActivate
return
Button:
SendInput, {F4}
return
答案 1 :(得分:0)
您的问题似乎是如何切换回原始应用程序,以便将数据发送到那里,而不是发送给AHK本身。
我在下面粘贴了一个例子供你观看。在第83行附近,您将看到我首先检查哪个窗口处于活动状态,然后在发送实际数据之前,如果需要,使用!{Esc}切换回上一个窗口。这只是我很久以前写的一个练习,用于创建多个粘贴选项。我确信丢失的东西可以改进,但它会让你知道如何解决这个问题。
#SingleInstance Force
#installKeybdHook
#Persistent
; Written by Robert Ilbrink, The Netherlands
Menu, Tray, Icon , Shell32.dll, 247, 1
SetTitleMatchMode, 2
Global Nr := 1
Next=Copy
x:=A_ScreenWidth-250
y:=A_ScreenHeight/2
; ================================== GUI ==================================
ShowListBox:
Gui, +Resize
Gui, Add, ListBox, h270 w195 vMyListBox gMyListBox, 01 %Array_1%|02 %Array_2%|03 %Array_3%|04 %Array_4%|05 %Array_5%|06 %Array_6%|07 %Array_7%|08 %Array_8%|09 %Array_9%|10 %Array_10%|11 %Array_11%|12 %Array_12%|13 %Array_13%|14 %Array_14%|15 %Array_15%|16 %Array_16%|17 %Array_17%|18 %Array_18%|19 %Array_19%|20 %Array_20%
;Gui, Add, Button, x10 y275 w45 h20, Paste
Gui, Add, Button, x10 y275 w45 h20, Refresh
Gui, Add, Button, x60 y275 w45 h20, Help
Gui, Add, Button, x110 y275 w45 h20, Special
Gui, +AlwaysOnTop
WinGet, State, MinMax,
If (State = -1)
Return
Else
Gui, Show, x%x% y%y%,Clippy CapsLock = %Next%
Return
GuiSize:
GuiControl, Move, MyListBox, % "w" A_GuiWidth - 20
GuiControl, Move, MyListBox, % "h" A_GuiHeight - 30
GuiControl, Move, Refresh, % "y" A_GuiHeight - 25
GuiControl, Move, Help, % "y" A_GuiHeight - 25
GuiControl, Move, Special, % "y" A_GuiHeight - 25
return
; ================================== SHORTCUTS ==================================
;+^1::MySend(Array_1) ; [Shift]+[Ctrl]+1 pastes item 1
;+^2::MySend(Array_2) ; [Shift]+[Ctrl]+2 pastes item 2
;+^3::MySend(Array_3) ; [Shift]+[Ctrl]+3 pastes item 3
;+^4::MySend(Array_4) ; [Shift]+[Ctrl]+4 pastes item 4
;+^5::MySend(Array_5) ; [Shift]+[Ctrl]+5 pastes item 5
;+^6::MySend(Array_6) ; [Shift]+[Ctrl]+6 pastes item 6
;+^7::MySend(Array_7) ; [Shift]+[Ctrl]+7 pastes item 7
;+^8::MySend(Array_8) ; [Shift]+[Ctrl]+8 pastes item 8
;+^9::MySend(Array_9) ; [Shift]+[Ctrl]+9 pastes item 9
;+^0::MySend(Array_10) ; [Shift]+[Ctrl]+0 pastes item 10
;+^q::MySend(Array_11) ; [Shift]+[Ctrl]+q pastes item 11
;+^w::MySend(Array_12) ; [Shift]+[Ctrl]+w pastes item 12
;+^e::MySend(Array_13) ; [Shift]+[Ctrl]+e pastes item 13
;+^r::MySend(Array_14) ; [Shift]+[Ctrl]+r pastes item 14
;+^t::MySend(Array_15) ; [Shift]+[Ctrl]+t pastes item 15
;+^y::MySend(Array_16) ; [Shift]+[Ctrl]+y pastes item 16
;+^u::MySend(Array_17) ; [Shift]+[Ctrl]+u pastes item 17
;+^i::MySend(Array_18) ; [Shift]+[Ctrl]+i pastes item 18
;+^o::MySend(Array_19) ; [Shift]+[Ctrl]+o pastes item 19
;+^p::MySend(Array_20) ; [Shift]+[Ctrl]+p pastes item 20
; ================================== NUMPAD SHORTCUTS ==================================
#Numpad1::MySend(Array_1) ; [Win]+1 pastes item 1
#Numpad2::MySend(Array_2) ; [Win]+2 pastes item 2
#Numpad3::MySend(Array_3) ; [Win]+3 pastes item 13
#Numpad4::MySend(Array_4) ; [Win]+4 pastes item 4
#Numpad5::MySend(Array_5) ; [Win]+5 pastes item 5
#Numpad6::MySend(Array_6) ; [Win]+6 pastes item 6
#Numpad7::MySend(Array_7) ; [Win]+7 pastes item 7
#Numpad8::MySend(Array_8) ; [Win]+8 pastes item 8
#Numpad9::MySend(Array_9) ; [Win]+9 pastes item 9
#Numpad0::MySend(Array_10) ; [Win]+0 pastes item 10
+#Numpad1::MySend(Array_11) ; [Shift]+[Win]+1 pastes item 11
+#Numpad2::MySend(Array_12) ; [Shift]+[Win]+2 pastes item 12
+#Numpad3::MySend(Array_13) ; [Shift]+[Win]+3 pastes item 13
+#Numpad4::MySend(Array_14) ; [Shift]+[Win]+4 pastes item 14
+#Numpad5::MySend(Array_15) ; [Shift]+[Win]+5 pastes item 15
+#Numpad6::MySend(Array_16) ; [Shift]+[Win]+6 pastes item 16
+#Numpad7::MySend(Array_17) ; [Shift]+[Win]+7 pastes item 17
+#Numpad8::MySend(Array_18) ; [Shift]+[Win]+8 pastes item 18
+#Numpad9::MySend(Array_19) ; [Shift]+[Win]+9 pastes item 19
+#Numpad0::MySend(Array_20) ; [Shift]+[Win]+0 pastes item 20
; ================================== SEND FUNCTION ==================================
MySend(Item)
{
ClipBoard = %Item%
IfWinActive, MultiClipBoard
Send, !{Esc}
Sleep, 100
Send, ^v{Space}
}
; ================================== SINGLE or DOUBLE CLICK ==================================
MyListBox: ; Single Click (Normal) or Double Click (DoubleClick) to paste data back to other application
if A_GuiControlEvent <> Normal ; Alternatively use "DoubleClick"
return
GuiControlGet, MyListBox ; Retrieve the ListBox's current MultiClipBoard.
StringTrimLeft, ClipBoard, MyListBox, 3
Send, !{Esc}
Sleep, 200
Send, ^v
;Send, {Enter}
;SendInput, %MyListBox%{Tab}
return
; ================================== PASTE BUTTON ==================================
ButtonPaste: ; Select an item with [Up] / [Down] arrows and press [Paste] to paste data back to other application
Gui, Submit, NoHide
StringTrimLeft, ClipBoard, MyListBox, 3
Send, !{Esc}
Sleep, 200
Send, ^v
;SendInput, %MyListBox%{Tab}
Return
; ================================== EXIT / CLOSE BUTTONS ==================================
GuiClose:
GuiEscape:
Gui, Destroy
ExitApp
; ================================== REFRESH BUTTON ==================================
ButtonRefresh:
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Return
; ================================== Copy Into the List ==================================
Browser_Favorites:: ; [Star] key to copy to clipboard.
!c:: ; [Alt]+c to copy to multiClipboard.
#c:: ; [Win]+c to copy to multiClipboard.
Send, ^c
Sleep, 100
Array_%Nr% := ClipBoard
Nr++
If (Nr >20) ; wrap around after 20 entries
Nr:=1
WinGet, State, MinMax, MultiClipBoard
If (State = -1)
Return ; GUI, Show
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Return
; ================================== CLEAR / OPEN / SAVE ==================================
ButtonSpecial:
SetTimer, ChangeButtonNames, 30
MsgBox, 4098, Special Action, [Clear]`, Clears all items`n[Open]`, Open a list`n[Save]`, Save current list.
IfMsgBox, Abort ; ================================== CLEAR ==================================
{
MsgBox, 4100,, Are you sure to clear the list?
IfMsgBox No
Return
Nr := 1
Loop, 20
{
Array_%Nr% =
Nr++
}
Nr := 1
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Exit
}
Else ifMsgBox, Retry ; ================================== OPEN ==================================
{
FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.txt)
If SelectedFile =
Exit
Else
{
Loop, read, %SelectedFile%
{
If A_LoopReadLine =
Break
Array_%A_Index% := A_LoopReadLine
If (A_Index > 20)
Break
Nr := A_Index + 1
}
}
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Exit
}
Else ifMsgBox, Ignore ; ================================== SAVE ==================================
{
FileSelectFile, SelectedFile, S, , Save the list as a Text Document, (*.txt)
StringReplace, SelectedFile, SelectedFile, `.txt,
FileDelete, %SelectedFile%.txt
Loop, 20
{
CurrentLine := Array_%A_Index%
FileAppend, %CurrentLine%`n, %SelectedFile%.txt ; % Array_%A_Index%, doesn't work
}
}
Exit
; ================================== HELP BUTTON ==================================
ButtonHelp:
MsgBox, , MultiClipBoard Help, Press [Alt]+c or [Win]+c to copy highlighted data onto the clipboard (TEXT only).`n`nClick on an item to paste it to the last active application.`n`nPress [Refresh] to refresh the screen after items were added while minimized.`n`nPress [Special] to select`n[Clear] to clear the list (after confirmation),`n[Load] to load items from a file or`n[Save] to save current items to a file. `n`n[Shift]+[Ctrl]+[nr] (1...0) will paste item 1...10.`n[Shift]+[Ctrl]+[letter] (qwertyuiop) will paste item 11...20.
; ================================== RENAME STANDARD MSGBOX BUTTONS FOR SPECIAL MENU ==================================
ChangeButtonNames:
IfWinNotExist, Special Action
return ; Keep trying.
SetTimer, ChangeButtonNames, off
WinActivate
ControlSetText, Button1, &Clear
ControlSetText, Button2, &Open
ControlSetText, Button3, &Save
return
; ================================== ToggleCopy ==================================
CapsLock::
Send % "{CTRL DOWN}" (!paste ? "c" : "v") "{CTRL UP}"
;SoundBeep, % (!paste ? "300" : "3000"), 100
paste := !paste
;SplashTextOn, 150, 20,%WindowTitle%, % (!paste ? "Press " MyKey " to Copy" : "Press " MyKey " to Paste")
;WinMove, %WindowTitle%, , 800, 5
Menu, Tray, Icon , Shell32.dll, % (paste ? "248" : "247"), 1 ; Toggle between Up/Down Arrow in Icon
Next:=(!paste ? " Copy" : " Paste")
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Send, !{Esc}
Return
; ================================== END ==================================