如何为敲击的键与按住 1000 毫秒的键制作不同的热键

How to make different hotkeys for a key being tapped vs a key being held for 1000ms

例如,我想在 ahk 中设置一个计时器,如果按住某个键的时间少于 1000 毫秒,它就会更改为例如。 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