Launching function on HOTKEY HOLD for specified time, else send normal key
Posted: 13 Jun 2019, 14:06
I searching whole day and can't find right, working answer.
I want to launch my function mToggler() only when holding Win keys (left or right) for more than 800 ms.
But on the other hand I want not to lose bringing Start Menu with this hotkey short tap nor other Win+<key> shortcuts (like Win+D for Show Desktop).
Because I working on an "module" script code this will be #included in other main AHK script file, so I define hotkey by Hotkey command, not :: hotkey definition:
and I would like to avoid labeling, because it can mess with auto-execute section in main script.
I tried many solutions but none working fine.
My last try was something like this, but there are some glitches:
- not work with shortcuts like Win+D
- multiple hold-hotkey fires, when hotkey is hold much longer than initial threshold time (e.g few seconds)
Can anyone advise that this is the best (or at least good and reliable) solution for hotkey hold detection?
And how modify it to fix above two glitches?
I want to launch my function mToggler() only when holding Win keys (left or right) for more than 800 ms.
But on the other hand I want not to lose bringing Start Menu with this hotkey short tap nor other Win+<key> shortcuts (like Win+D for Show Desktop).
Because I working on an "module" script code this will be #included in other main AHK script file, so I define hotkey by Hotkey command, not :: hotkey definition:
Code: Select all
Hotkey, LWin, mToggler
I tried many solutions but none working fine.
My last try was something like this, but there are some glitches:
- not work with shortcuts like Win+D
- multiple hold-hotkey fires, when hotkey is hold much longer than initial threshold time (e.g few seconds)
Code: Select all
mToggler()
{
KeyWait, %A_ThisHotkey%, U T0.8
If (!ErrorLevel) { ; short tap
SoundBeep 2000, 50
Send {%A_ThisHotkey% Down}
Send {%A_ThisHotkey% Up}
} else { ; hold detected
SoundBeep 200, 200
; ... rest of the function code ...
}
}
Hotkey, LWin, mToggler
And how modify it to fix above two glitches?