1
votes

I’m having some trouble with Autohotkey. I have a script with a few hotkeys but it seems that when a hotkey is pressed, not only does its handler run, but so do all lines below it, including the contents of other hotkey handlers. Below is a demonstrative example.

What is the problem? How can I get Autohotkey to execute only the lines specified in the handler?


#SingleInstance force

;Main loop
While 1
{
}

;Hotkeys:

;Quit with Ctrl+Q
^q::
{
    MsgBox  Quitting
    ExitApp
}

^s::
{
    MsgBox  Hotkey1
}
MsgBox 1

^a::
{
    MsgBox  Hotkey2
}
MsgBox 2
1
What the? What’s wrong with the question? Hit-and-run down-voters. :roll:Synetech

1 Answers

2
votes

I am missing the return command:

^s::
    MsgBox  Hotkey1
return

MsgBox 1


^a::
    MsgBox  Hotkey2
return

MsgBox 2

I guess I’m just too used to more strict C++ syntax; the braces don’t quite work the same way. I’ll just have to think back to the good old days of Basic and Assembler when working with Autohotkey scripts.