Sets a hotkey that calls a user function.
HotKeySet ( "key" [, "function"] )
Parameters
| key | The key combination to use as the hotkey. Same format as Send(). |
| function | [optional] The name of the function to call when the key is pressed. Not specifying this parameter will unset a previous hotkey. |
Return Value
| Success: | Returns 1. |
| Failure: | Returns 0. |
Remarks
If two AutoIt scripts set the same HotKeys, you should avoid running those scripts simultaneously. (The second script cannot capture the hotkey unless the first script terminates or unregisters the key prior to the second script setting the hotkey.)| Ctrl+Alt+Delete | It is reserved by Windows |
| F12 | It is also reserved by Windows, according to its API. |
| NumPad's Enter Key | Instead, use {Enter} which captures both Enter keys on the keyboard. |
| Win+B,D,E,F,L,M,R,U; and Win+Shift+M | These are built-in Windows shortcuts. Note: Win+B and Win+L might only be reserved on Windows XP and above. |
| Alt, Ctrl, Shift, Win | These are the modifier keys themselves! |
| Other | Any global hotkeys a user has defined using third-party software, any combos of two or more "base keys" such as '{F1}{F2}', and any keys of the form '{LALT}' or '{ALTDOWN}'. |
Related
Send, GUISetAccelerators
Example
; Press Esc to terminate script, Pause/Break to "pause"
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d
;;;; Body of program would go here ;;;;
While 1
Sleep(100)
WEnd
;;;;;;;;
Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc
Func Terminate()
Exit 0
EndFunc
Func ShowMessage()
MsgBox(4096,"","This is a message.")
EndFunc