Also you can add a ToolTip to
Rohwedder's solution. I don't recommend using Soundbeeps here since they eat some time.
Code: Select all
$*enter::
Send {Blind}{enter}
SetTimer, Tip, 100
KeyWait, enter, T1.0 ;press the enter key for 1 second
If ErrorLevel
Send {Esc}
KeyWait, enter, T.5 ;press the enter key for 1 + .5 second
If ErrorLevel
Send !{f4}
KeyWait, enter
SetTimer, Tip, Off
ToolTip
return
Tip:
switch time := Round(A_TimeSinceThisHotkey/1000, 1) {
case 1: ToolTip, ESC ESC ESC`nESC ESC ESC`nESC ESC ESC
case 1.5: ToolTip, Alt+F4 Alt+F4 Alt+F4`nAlt+F4 Alt+F4 Alt+F4`nAlt+F4 Alt+F4 Alt+F4
Default: ToolTip, % time " seconds"
}
return
If you don't want to send {Esc} in case of held longer than 1.5 sec and send only Alt+F4 in that case, you may delay sending of Esc until you release the button and calculate the output:
Code: Select all
$*enter::
Send {Blind}{enter}
SetTimer, Tip, 100
KeyWait, enter, T1.0 ;press the enter key for 1 second
If ErrorLevel
{ KeyWait, enter, T.5 ;press the enter key for 1 + .5 second
If ErrorLevel
{ Send !{f4}
KeyWait, enter
}
else Send {Esc}
}
SetTimer, Tip, Off
ToolTip
return
Tip:
switch time := Round(A_TimeSinceThisHotkey/1000, 1) {
case 1: ToolTip, ESC ESC ESC`nESC ESC ESC`nESC ESC ESC
case 1.5: ToolTip, Alt+F4 Alt+F4 Alt+F4`nAlt+F4 Alt+F4 Alt+F4`nAlt+F4 Alt+F4 Alt+F4
Default: ToolTip, % time " seconds"
}
return
P.S.
Add code tags, please, otherwise you make moderators to add them in your post.