Funciona melhor usando o SetTimer:
; The following hotkeys work only if MS-WORD is the active window:
#If WinActive("ahk_exe WINWORD.EXE") ; (1)
1::
if 1_presses > 0
{
1_presses += 1
SetTimer Key1, 300
return
}
1_presses = 1
SetTimer Key1, 300
return
Key1:
SetTimer Key1, off
if 1_presses = 2
SendInput, BYE
else
SendInput, HELLOW
1_presses = 0
return
F2:: MsgBox, You pressed F2 in MS-Word
; The following hotkeys work only if NOTEPAD is the active window:
#If WinActive("ahk_exe NOTEPAD.EXE")
1:: Send 2
F2:: MsgBox, You pressed F2 in NOTEPAD
#If ; turn off context sensitivity (= end of context-sensitive hotkeys)
; The following hotkeys work only if MS-WORD or NOTEPAD is NOT the active window (because they are already defined in those programs):
1:: Send 3
F2:: MsgBox, You pressed F2 while MS-WORD or NOTEPAD is NOT the active window
; The following hotkeys work in all windows (incl. MS-WORD and NOTEPAD because they are NOT defined in those programs)
F3:: MsgBox, You pressed F3
Esc:: ExitApp
link (Exemplo # 3)
(1) Assim como as diretivas #IfWin , #If cria hotkeys e hotstrings sensíveis ao contexto e é posicional: afeta todas as hotkeys e hotstrings fisicamente abaixo dele no script.