Variable Hotkey: Only execute when pressed certain time or longer Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
list
Posts: 222
Joined: 26 Mar 2014, 14:03
Contact:

Variable Hotkey: Only execute when pressed certain time or longer

09 Jul 2023, 07:27

I'm having a bit of a brain fart, I have a hotkey defined in variable (read from ini) and I only want it execute the label when it has been pressed / released after a set time (also variable), if you quickly tap the hotkey nothing should happen.
For single key hotkeys (e.g. capslock, space, etc) it is easy to use keywait, but I can't wrap my head around something like if (A_ThisHotkey = A_PriorHotkey) && (A_TimeSincePriorHotkey < 1000)

Code: Select all

#singleinstance, force

hk:="^b"
duration:=1000

Hotkey, %hk%, labelwait
Return

labelwait:
; check if hotkey is pressed for "duration" before continuing 
; if hotkey is released before "duration" has passed simply return (do nothing)
 
Return
User avatar
mikeyww
Posts: 26979
Joined: 09 Sep 2014, 18:38

Re: Variable Hotkey: Only execute when pressed certain time or longer  Topic is solved

09 Jul 2023, 07:58

Code: Select all

labelwait:
hk := RegExReplace(A_ThisHotkey, "[#^+!]")
KeyWait % hk, % "T" duration / 1000
If !ErrorLevel
 Return
MsgBox 123
KeyWait % hk
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: GEOVAN, nacken012 and 70 guests