I have a long AHK script with lots of simple {tab} and {down} etc...

If something goes wrong, I need to terminate the script. Googled, found lots of answers, mostly saying:

put esc::ExitApp at the end of the script

It just does not work for me... Code:


SetKeyDelay, 1000   ; set to see if the rapid key execution was preventing the esc::exitapp to work, but makes no difference.

send, !f {Right}{enter}
send, {TAB 3} {Down 20} 

; lots more {tab}'s and {enter}'s

Return   ; I remember to put it


I run the script, test Esc - it works.

I press ^#i, the execution starts, and Esc does not work anymore, as if ^#i had overriding priority...

EDIT: interesting thing is that if I manually click the tray icon and click pause script, my ^#i keeps executing, only manual "exit script" works...


I'm not exactly sure what's causing your issue, as I can't seem to replicate it on my machine. But you can try using SetTimer instead with your hotkey.

This might allow you to get around any blocking behavior.

; Bind the keybind to SetTimer
^#i::SetTimer, MySub, -1

; Declare the subroutine the timer triggers
    ; Execute more code here...
    ; ...
    ; ...


[after much frustration]

All new scripts come with this at the top:

 SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.

This command prevents SetKeyDelay, so i commented it out. BUT this then disables all Exitapp, suspend, reload, etc...

I reenabled SendMode Input and all suggestions from the internet work. Except that I'm left without SetKeyDelay again...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.