我是AHK的新手,我希望Autohotkey能够在MS Word类型的HELLOW中按热键“ 1”,但是同时在同一应用程序(MS Word)中,我希望组合键“ 11”(按了键1)快两次)以输入BYE,这可能吗?当我输入“ 1”时,AHK将输入“ 1HELLOW”,当我输入“ 11”时,它将输入“ 11BYE”吗?是否可以用F1做相同的脚本?我的意思是F1,以及键序列F1F1(F1快速按了两次)
到目前为止,我已经尝试过
~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
但是它只是在我第一次按下按键序列11(一次快速按下两次)时才起作用,然后它始终只能识别1个按键,为什么???
~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
这也无助于获得两个热键(1和11)。
谢谢先进。
使用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
https://autohotkey.com/docs/commands/SetTimer.htm#Examples(示例3)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句