$Escape:: ; Long press (> 0.5 sec) on Esc closes window
KeyWait, Escape, T0.5 ; Wait no more than 0.5 sec for key release (also suppress auto-repeat)
If ErrorLevel ; timeout, so long press
PostMessage, 0x112, 0xF060,,, A ; ...close window
Else ; otherwise...
Send {Esc} ; ...just send Escape
ReturnThis works quite well, but I found that sometimes you press Esc by mistake, and you wish there was a way to back out. So this is what I came up with:
$Escape:: ; Long press (> 0.5 sec) on Esc closes window - but if you change your mind you can keep it pressed for 3 more seconds
KeyWait, Escape, T0.5 ; Wait no more than 0.5 sec for key release (also suppress auto-repeat)
If ErrorLevel ; timeout, so key is still down...
{
KeyWait, Escape, T3 ; Wait no more than 3 more sec for key to be released
If !ErrorLevel ; No timeout, so key was released
{
PostMessage, 0x112, 0xF060,,, A ; ...so close window
Return
}
; Otherwise,
KeyWait, Escape ; Wait for button to be released
; Then do nothing...
Return
}
Send {Esc}
ReturnAnd, since I never can let anything be, a version with bells and whistles:
$Escape:: ; Long press (> 0.5 sec) on Esc closes window - but if you change your mind you can keep it pressed for 3 more seconds
KeyWait, Escape, T0.5 ; Wait no more than 0.5 sec for key release (also suppress auto-repeat)
If ErrorLevel ; timeout, so key is still down...
{
SoundPlay *64 ; Play an asterisk (Doesn't work for me though!)
WinGet, X, ProcessName, A
SplashTextOn,,150,,`nRelease button to close %x%`n`nKeep pressing it to NOT close window...
KeyWait, Escape, T3 ; Wait no more than 3 more sec for key to be released
SplashTextOff
If !ErrorLevel ; No timeout, so key was released
{
PostMessage, 0x112, 0xF060,,, A ; ...so close window
Return
}
; Otherwise,
SoundPlay *64
KeyWait, Escape ; Wait for button to be released
; Then do nothing...
Return
}
Send {Esc}
Return




