Autohotkey and ExitApp: how to enable and disable ESC key to work just in a part of the script?

StackOverflow https://stackoverflow.com/questions/23159145

  •  05-07-2023
  •  | 
  •  

문제

I have a very long script and I want to stop it with ESC key if it goes astray.

So I have put in the script this line:

Esc::ExitApp

But, of course, sometimes I have to press ESC key even when not running the script and when I need AutoHotkey, it's gone.

How do I tie ExitApp to ESC key just for a part of the script that's running?

도움이 되었습니까?

해결책 2

this code is working:

Esc::goto ExitThisProgramQuestion

ExitThisProgramQuestion:
    MsgBox, 4, , Are we exiting? 
    IfMsgBox, No
        return
    ExitApp
return

다른 팁

You have to add ExitApp as a command in your script! It is a special kind of label, not a function. If the label doesn't exist in your script, you can't call it.

To make it exist, just add another line with the label on it. -->>**actually, I was wrong to say that. In the docs it gives the example that you can use simply Esc::ExitApp just like that to exit the running script ExitApp exists in the script even if you don't create it first because it's built into AutoHotkey. However, with your new code from your comment, you can use a custom label (which does have to exist in your script before you can call it):

Esc::goto DoSomething

DoSomething:
    MsgBox, 4, , Are we exiting? 
    IfMsgBox, No
        return  ;after this return, the next line will not be called.
    ExitApp  ;as soon as this is called, the script ends completely and no more of the script will ever be called
return
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top