Hotkey Command Below Double Colon Hotkey Does Not Work

Get help with using AutoHotkey and its commands and hotkeys
TheMaxx
Posts: 8
Joined: 28 Mar 2019, 15:14

Hotkey Command Below Double Colon Hotkey Does Not Work

08 Aug 2020, 09:07

----------

file1.ahk - in this code f1 works:

----------

Code: Select all

hotkey, f1, mylabel

f2::msgbox, you pressed f2

mylabel:
msgbox, you pressed f1
return
----------

file2.ahk - in this code f1 does not work:

----------

Code: Select all

f2::msgbox, you pressed f2

hotkey, f1, mylabel

mylabel:
msgbox, you pressed f1
return
----------

why? thanks.

----------

seems to have something to do with the auto-execute section documented at:
https://www.autohotkey.com/docs/Scripts.htm#auto
as stated in the first sentence?

----------
Last edited by TheMaxx on 08 Aug 2020, 09:22, edited 2 times in total.
gregster
Posts: 4917
Joined: 30 Sep 2013, 06:48

Re: Hotkey Command Below Double Colon Hotkey Does Not Work

08 Aug 2020, 09:20

In the second script, hotkey, f1, mylabel is unreachable code, it won't ever be executed.

A one-line hotkey, like f2::.. here, has an implicit return, that's why the flow of execution won't reach that line beneath it.

In the first script, that line is part of the auto-execute section at the top of the script, which - for example - ends at the first hotkey definition, but will be executed at script start...
TheMaxx
Posts: 8
Joined: 28 Mar 2019, 15:14

Re: Hotkey Command Below Double Colon Hotkey Does Not Work

08 Aug 2020, 09:59

Thanks for the information. I kind of thought that the "hotkey command" (hotkey, f1, mylabel) worked the same way as the single line "hotkey label" (f2::msgbox, you pressed f2) but now i know that hotkey commands should be put in the AES (Auto-Execute Section) before hotkey labels. I'll have to learn the AHK terminology better! Thanks again.

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Azev, effel and 55 guests