Execute ExitApp command if the "End" key is pressed for 3 seconds Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Execute ExitApp command if the "End" key is pressed for 3 seconds

15 Oct 2021, 09:42

I want if End Key is pressed for 3 seconds or more, the code executes ExitApp command .
And in the case the key has been pressed for less than 3 seconds, I do not want anything to happen, and execute the normal function of the key is executed as usual.

This is my attempt, but I don't know why it comes out of the code even if the required key has been pressed for less than 3 seconds

Code: Select all

$End::
KeyWait, End, t.3
IF ErrorLevel
	SoundBeep, 800, 400
Else
ExitApp
KeyWait, End
ToolTip,% "U have been pressed End " A_TimeSinceThisHotkey " ms"
Return
And in the same code above, but writing the Q key instead of End and in this attempt it works fine.

Code: Select all

$q::
KeyWait, q, t.3
IF ErrorLevel
	SoundBeep, 800, 400
Else
SendInput, q
KeyWait, q
ToolTip,% "U have been pressed Q " A_TimeSinceThisHotkey " ms"
Return
How can I fix this problem,
Thanks you
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Execute ExitApp command if the "End" key is pressed for 3 seconds  Topic is solved

15 Oct 2021, 10:02

Code: Select all

$End::
   KeyWait, End, t.3          ; wait for 0.3 seconds for the End key to be released
   IF ErrorLevel              ; if the KeyWait timed out (the key was pressed for more than 0.3 seconds)
      SoundBeep, 800, 400        ; beep
   Else                       ; otherwise (the key was pressed for less than or exactly 0.3 seconds)
      ExitApp                    ; terminate the script
   KeyWait, End               ; ???
   ToolTip,% "U have been pressed End " A_TimeSinceThisHotkey " ms"
Return
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Execute ExitApp command if the "End" key is pressed for 3 seconds

15 Oct 2021, 10:11

Sorry for my bad Indentation :oops: ,
I deleted line number 7, but the problem is still
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Execute ExitApp command if the "End" key is pressed for 3 seconds

15 Oct 2021, 11:42

Sorry,
I misunderstood you comments in the code you posted,
I solved the problem now, Thanks..

Code: Select all

$End::
   KeyWait, End, t.3          ; wait for 0.3 seconds for the End key to be released
   IF ErrorLevel              ; if the KeyWait timed out (the key was pressed for more than 0.3 seconds)
      ExitApp                    ; terminate the script
   else
      Send, {End}
   ToolTip,% "U have been pressed End " A_TimeSinceThisHotkey " ms"
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: downstairs, OrangeCat and 186 guests