Reputation: 43
For example I want to set a timer in ahk where if a key is held for less than 1000ms it is changed to eg. Esc, and if it is held for more than a second some other script is executed?
Thank you in advance.
Upvotes: 1
Views: 249
Reputation: 779
I believe this code forums may help you.
Source: 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
Upvotes: 1