Sets a hotkey that calls a user function.
HotKeySet ( "key" [, "function"] )
It is recommended to use lower-case keys/characters (e.g. "b" and not "B") when setting hotkeys to avoid errors as with some keyboard layouts upper and lower case keys may be mapped differently.
Keyboard with 102 keys as the Hungarian keyboard need to use "{OEM_102}" to capture the "í" key.
If two AutoIt scripts set the same hotkeys, you should avoid running those scripts simultaneously as the second script cannot capture the hotkey unless the first script terminates or unregisters the key prior to the second script setting the hotkey. If the scripts use GUIs, then consider using GUISetAccelerators as these keys are only active when the parent GUI is active.
A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function until it completes or is interrupted. Exceptions are as follows:
1) If the current function is a "blocking" function, then the key-presses are buffered and execute as soon as the blocking function completes. MsgBox() and FileSelectFolder() are examples of blocking functions. Try the behavior of Shift-Alt-d in the Example.
2) If you have paused the script by clicking on the AutoIt Tray icon, any hotkeys pressed during this paused state are ignored.
The following hotkeys cannot be set:
#include <MsgBoxConstants.au3>
; Press Esc to terminate script, Pause/Break to "pause"
Global $g_bPaused= False
HotKeySet ("{PAUSE}","TogglePause")
HotKeySet ("{ESC}","Terminate")
HotKeySet ("+!d","ShowMessage"); Shift-Alt-d
While 1
Sleep (100)
WEnd
Func TogglePause()
$g_bPaused= Not $g_bPaused
While $g_bPaused
Sleep (100)
ToolTip ('Script is "Paused"',0,0)
WEnd
ToolTip ("")
EndFunc ;==>TogglePause
Func Terminate()
Exit
EndFunc ;==>Terminate
Func ShowMessage()
MsgBox ($MB_SYSTEMMODAL,"","This is a message.")
EndFunc ;==>ShowMessage
#include <MsgBoxConstants.au3> ; Press Esc to terminate script, Pause/Break to "pause" Global $g_bPaused= False HotKeySet ("{PAUSE}","HotKeyPressed") HotKeySet ("{ESC}","HotKeyPressed") HotKeySet ("+!d","HotKeyPressed"); Shift-Alt-d While 1 Sleep (100) WEnd Func HotKeyPressed() Switch @HotKeyPressed ; The last hotkey pressed. Case "{PAUSE}"; String is the {PAUSE} hotkey. $g_bPaused= Not $g_bPaused While $g_bPaused Sleep (100) ToolTip ('Script is "Paused"',0,0) WEnd ToolTip ("") Case "{ESC}"; String is the {ESC} hotkey. Exit Case "+!d"; String is the Shift-Alt-d hotkey. MsgBox ($MB_SYSTEMMODAL,"","This is a message.") EndSwitch EndFunc ;==>HotKeyPressed