Leon Fasser
Leon Fasser

Reputation: 43

How can you make the output of a key dependent on the duration which it is pressed. (in ahk, Autohotkey)

Basically what I want is the F9 key to be transformed into Ctrl+W when it is pressed for under 500ms and into Esc for any duration above 500ms. Thx

Upvotes: 0

Views: 221

Answers (1)

Relax
Relax

Reputation: 10543

$F9::
Keywait, F9, T0.5 ; waits 0.5 seconds maximally for F9 to be released
if ErrorLevel     ; pressed for above that time
     Send ^w
else
     Send {Esc}
Return

or

$F9::
Keywait, F9, T0.5 ; waits 0.5 seconds maximally for F9 to be released
if ErrorLevel     ; pressed for above that time
{
     KeyWait, F9  ; wait for F9 to be released
     Send ^w    
}
else
     Send {Esc}
Return

https://www.autohotkey.com/docs/commands/KeyWait.htm

Upvotes: 1

Related Questions