例如,我想在ahk中设置一个计时器,如果一个键被保持的时间少于1000ms,它将被更改为eg。Esc,如果它被保持超过一秒钟,一些其他脚本被执行?
提前谢谢你。
我相信这个代码论坛可能会对你有所帮助。
来源:https://www.autohotkey.com/boards/viewtopic.php?t=82436
; triple Tap or Hold key snippet
;?????????????????????????????????????? .----------------------------------------+
return ; ¦
Timer: ; - - triple Tap + Hold - BLOCK 1 - - ¦
{ ; This is the block that starts ¦
If !%A_ThisHotkey%key ; the count forall Hotkeys. ¦
SetTimer, %A_ThisHotkey%key, -400 ; Make sure it is placed above ¦
%A_ThisHotkey%key++ ; Block 2 & that the prefix is changed ¦
Return ; to match the key's Name, as only 1 ¦
} ; may Exist. instance of this lable ¦
;______________________________________/ `----------------------------------------+
Q:: goto timer
;???????????????????????????????????????????
qkey: ; +------------------+
If GetKeyState("q","P") and %A_ThisLabel%=1 ;>----------¦ Hold Action ¦
msgbox you held down the key Q ; +------------------+
; - - - - - - - - - - - - - - +
Else If %A_ThisLabel% = 3 ; +------------------+
msgbox you pressed the key Q 3 times ;>----------¦ 3X Press Action ¦
; - - - - - - - - - - - - - - + +------------------+
Else If %A_ThisLabel% = 2 ; +------------------+
msgbox you pressed the key Q 2 times ;>----------¦ 2X Press Action ¦
; - - - - - - - - - - - - - - + +------------------+
Else If %A_ThisLabel% = 1 ; +------------------+
msgbox you pressed the key Q 1 time ;>----------¦ 1X Press Action ¦
; - - - - - - - - - - - - - - + +------------------+
%A_ThisLabel%=0 ;
return ;
;___________________________________________/
key:
return