Im pretty new in AHK, I would like Autohotkey to whenever I press the hotkey "1" in MS Word type HELLOW, but at the same time in the same app (MS Word) I want the key combination "11" (key 1 pressed two times very quickly) to type BYE, is this possible? will AHK type "1HELLOW" when I type "1", will it type "11BYE" when I type "11"? is it possible to do the same script but with F1 instead? I mean F1, and the key sequence F1F1 (F1 pressed twice very quickly)
So far I have tried this
~1::
;400 is the maximum allowed delay (in milliseconds) between presses.
if (A_PriorHotKey = "~1" AND A_TimeSincePriorHotkey < 400)
{
Msgbox,Double press detected.
}
else if (A_PriorHotKey = "~1" AND A_TimeSincePriorHotkey > 400)
{
Msgbox,Single press detected.
}
Sleep 0
KeyWait 1
return
But it just work the first time I press the key sequence 11 (1 pressed twice quickly) then it will always recognize only the 1 key, why???
~1::
if (A_PriorHotkey <> "~1" or A_TimeSincePriorHotkey > 400)
{
; Too much time between presses, so this isn't a double-press.
KeyWait, 1
return
}
MsgBox You double-pressed the 1 key.
return
this doesn't help to get the two hotkeys, (1 and 11) either.
Thanks Advanced.
Best Answer
It works best by using SetTimer:
https://autohotkey.com/docs/commands/SetTimer.htm#Examples (Example #3)
(1) Like the #IfWin directives, #If creates context-sensitive hotkeys and hotstrings and is positional: it affects all hotkeys and hotstrings physically beneath it in the script.