Code: Select all
gui, add, button, gbutton, test
gui, show
return
button:
msgbox, a
F1::
F2::
F3::
msgbox, b
exitapp
Code: Select all
gui, add, button, gbutton, test
gui, show
return
button:
msgbox, a
F1::
F2::
F3::
msgbox, b
exitapp
Code: Select all
gui, add, button, gbutton, test
gui, show
return
button:
msgbox, a
mylabel:
MsgBox, b
ExitApp
F1::
F2::
F3::
goto mylabel
Why is that?
hence, it works as you want if you have another hotkey defined above the label, eg,auto execute section wrote:Note: While the script's first hotkey/hotstring label has the same effect as return, other hotkeys and labels do not.
Code: Select all
gui, add, button, gbutton, test
gui, show
esc::exitapp
button:
msgbox, a
F1::
F2::
F3::
msgbox, b
exitapp
jackdunning wrote:I should alter my post to state that only the Auto-Execute section terminates processing when encountering a Hotkey/Hotstring definition.
Thank you Helgef for the answer and reference. So the effect was documented after all.Helgef wrote:Why is that?hence, it works as you want if you have another hotkey defined above the labelauto execute section wrote:Note: While the script's first hotkey/hotstring label has the same effect as return, other hotkeys and labels do not.
Probably it is done this way to avoid the need to end the auto execute section with a return. Eg, you do not need to put a return above the hotkey in this script,Why is AutoHotkey designed that way? Is that a feature intentionally added to AutoHotkey because it is somehow useful?
Code: Select all
a::
msgbox
return
Ok, I can see some use for that. Though not below an auto execute section that already end with `return` like in my example.Helgef wrote:Probably it is done this way to avoid the need to end the auto execute section with a return.
But I suppose requesting that change is a non-starter since it could have unpredictable results in existing scripts.If the auto-execution section is not ended with Return then the script's first hotkey/hotstring label has the same effect as return. Later hotkeys and labels do not have that effect.
Not true. See Helgef's quote.jackdunning wrote:Hotkey and Hotstring definitions always stop regular AutoHotkey command processing such as subroutines and the Auto-Execute section,
If there's no return, how do we know at what point the auto-execute section is intended to end?askyq wrote:If the auto-execution section is not ended with Return then ...
Code: Select all
gui, add, button, gbutton, test
gui, show
return
button:
F1::
F2::
F3::
if (A_ThisLabel = "button")
msgbox, a
msgbox, b
exitapp
Useful, thanks.lexikos wrote:Pass-through works even for the first hotkey/hotstring if you place the label immediately above it
I don't know and your examples convince me of the complexity. But my (naive) suggestion was for when there *is* a Return. I was thinking only of "simple" cases like my example script, where the auto-execute section has no goto and end with a non-branched Return. But I get that AutoHotkey would then need to define and document a simple/non-simple distinction. Complexity seeps back in.lexikos wrote:If there's no return, how do we know at what point the auto-execute section is intended to end?askyq wrote:If the auto-execution section is not ended with Return then ...
I should alter my post to state that only the Auto-Execute section terminates processing when encountering a Hotkey/Hotstring definition. In subroutines, my testing shows that Hotkey/Hotstring definitions do indeed become invisible (pass through) when no action or text replacement appears to the right of the ::. However, unless I'm missing something, any Hotkey action on the same line (which does run) or a standard Hotstring with replacement text does stop processing. I suppose this is due to the Return being assumed in a single-line Hotkey.lexikos wrote:Not true. See Helgef's quote.
Code: Select all
MsgBox Auto-execute section
^1:: ; This acts as return.
MsgBox ^1 ; Not shown unless you press the hotkey.
; There is no return here.
^2:: ; This does not "stop processing".
MsgBox ^2 ; Shown if you press ^2 OR ^1.
^3::MsgBox ^3 ; ^3:: does not "stop processing".
; There is an implicit return in the above AFTER MsgBox.
Code: Select all
MsgBox, 0
;auto-execute section ends here (because of a hotkey label below)
;(hotkey labels by themselves are usually fallen through)
;(hotkey labels plus code 'one-liners' are usually fallen into but not fallen out of)
q::
MsgBox, 1
w::
MsgBox, 2
e::MsgBox, 3
MsgBox, 4
r::MsgBox, 5
MsgBox, 6
;hotkey and MsgBoxes triggered
;q 1 2 3
;w 2 3
;e 3
;r 5
;note: the line 'e::MsgBox, 3' contains an implicit return, thus: although it can be fallen into, it cannot be fallen out of
Code: Select all
Gosub MySub
return
MySub:
q::
MsgBox, 1
return
You are misrepresenting the facts. I just explained and we both demonstrated that execution falls through the hotkey label and executes the hotkey action. Anyone who thinks there will be no fall-through will be unpleasantly surprised.jeeswg wrote:;(hotkey labels plus code 'one-liners' are never fallen through)
Code: Select all
^1::if M(1)
^2::loop % M(2)
^3::M(3)
M(m) {
MsgBox % m
return 0
}
Code: Select all
^1::
if M(1)
return
^2::
loop % M(2)
return
^3::
M(3)
return
M(m) {
MsgBox % m
return 0
}
Code: Select all
MsgBox 0
if false ; 'Cancels' the implicit return before the first hotkey.
^1::MsgBox 1
Code: Select all
return ;or exit or exitapp
msgbox, a ;not auto-executed on script start
Code: Select all
F1:: var := 1 ;the end of this line returns
msgbox, a ;hence this msgbox is not executed on hotkey F1 press
Code: Select all
F1:: msgbox, a ;msgbox not auto-executed on script start since the F1 hotkey label returns
Code: Select all
gui, add, button, gbutton, test
gui, show
return
button:
var := 1
F1::
msgbox, a ;msgbox not executed on button "test" press
;because the script's first hotkey label F1 returns
Code: Select all
gui, add, button, gbutton, test
gui, show
return
button:
F1::
msgbox, a ;msgbox is executed on button "test" press
Code: Select all
gui, add, button, gbutton, test
gui, show
return
F2:: msgbox, b
button:
var := 1
F1::
msgbox, a ;executed on button "test" press
Code: Select all
gui, add, button, gbutton, test
gui, show
return
button:
var := 1
goto F1
F1:: ;script's first hotkey/hotstring label
msgbox, a ;executed when button "test" is pressed
Code: Select all
#FirstHotkeyReturn off
Users browsing this forum: boydfields, Google [Bot] and 158 guests