HotKeySet ("Hotkey" [, "Function Name"] )
parameter
Hotkey | The hotkey to set,Key format andSend()The same function is used. |
Function name | [Optional Parameters] The name of the function to be called after pressing the hotkey. Leave blank to undo the previously set hotkey. |
Return value
success: | The return value is 1. |
fail: | The return value is 0. |
Notice
Each script program can register up to 64 hotkeys at the same time.If two AutoIt scripts have the same hotkeys set, you should avoid running both scripts at the same time (otherwise the second script won't catch the hotkey unless the first script terminates running or the conflicting hotkey is revoked before the second script sets the hotkey).
After the user presses a hotkey, *usually* interrupts the currently running AutoIt function/statement and runs the user function associated with the hotkey until it completes the operation or is interrupted. Of course, there will be some exceptions:
1) If the current (running) function is a "blocking" function, the keystroke action will be buffered and the blocking function will be completed before continuing to execute. MsgBox and FileSelectFolder are typical blocking functions. You can try the hotkey Shift-Alt-d defined in the following example script.
2) If you select Pause script on the AutoIt tray menu, any hotkeys pressed during Pause will be ignored.
Hotkeys that cannot be set:
Ctrl+Alt+Delete | Reserved by Windows |
F12 | It is also reserved by Windows and involves APIs. |
Enter key on the keyboard | Use {Enter} to capture both the Enter keys on the primary and the keypad |
Win+B,D,E,F,L,M,R,U; and Win+Shift+M | These are the built-in shortcut keys for Windows. Note: Win+B and Win+L are reserved only by Windows XP and above systems. |
Alt, Ctrl, Shift, Win | These are auxiliary buttons! |
other | Any global hotkey defined by third-party software, any hotkey consisting of two or more "base keys" (such as '{F1}{F2}'), any key such as '{LALT}' or '{ALTDOWN}'. |
After setting a hotkey, AutoIt will try to capture the specified key event but will not pass it to the activation program, but there is an exception: Pressing the Lock key (including NumLock, CapsLock, and ScrollLock) will switch its corresponding state at any time! If you want to send the captured hotkey event to the activation program, you must log out the hotkey before calling itSendorControlSendfunction:
; Capture and pass key events
HotKeySet("{Esc}", "captureEsc")
Func captureEsc()
; ... Here you can define various tasks to do
HotKeySet("{Esc}")
Send("{Esc}")
HotKeySet("{Esc}", "captureEsc")
EndFunc
Related
Send, ControlSend
Example
; Pressing Esc will terminate the script, pressing Pause/Break will "pause"
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d
;;;; Here is the program body ;;;;
While 1
Sleep(100)
WEnd
;;;;;;;;
Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('The script has been "paused"',0,0)
WEnd
ToolTip("")
EndFunc
Func Terminate()
Exit 0
EndFunc
Func ShowMessage()
MsgBox(4096,"","This is a dialog box.")
EndFunc