Goto/Gosub send first hotkey of label

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Malek_Necibi
Posts: 4
Joined: 24 Oct 2017, 20:47

Goto/Gosub send first hotkey of label

24 Oct 2017, 21:12

[Moderator's note: Topic moved from Bug Reports.]

If the first line of a label is a remapping of a key, whenever a goto jumps to that label, the re-mapped key gets sent, even if the key isn't pushed.
In this case, the message box "2" should be sent regardless, but the Exit closes the script before the msgbox can be shown.
Sorry if this isn't a good description, this is my first time ever using the forum. :)

Code: Select all

Goto, Two

One:
MsgBox 1

Two:
a::Exit
MsgBox 2
return
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Goto/Gosub send first hotkey of label

24 Nov 2017, 01:32

This is by design.

Within a larger script, both labels ("Two" and "*a") would point at the next available line of executable code: Exit.

A subroutine ends only at a command flow statement, such as Return or Exit, not at a label. The only exception is the script's first hotkey, which is documented as ending the auto-execute section. (This is why the example you posted cannot be used to replicate the problem you described.)

To avoid confusion, note that a::Exit is a one-line hotkey, not a "remapping". "a::" is a label, similar to "one:", and stacks the same way. You cannot put one subroutine inside another (unless you skip over it with Goto), and that includes hotkey subroutines.
Malek_Necibi
Posts: 4
Joined: 24 Oct 2017, 20:47

Re: Goto/Gosub send first hotkey of label

26 Mar 2021, 13:26

Apologies for such a late response, but that makes a lot of sense now that you've explained the intent. Thank you so much for clearing this up, and have a great day!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: OrangeCat, scriptor2016 and 122 guests