Can GroupAdd only be used at the beginning of a script?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Coldblackice
Posts: 19
Joined: 13 Nov 2013, 14:39

Can GroupAdd only be used at the beginning of a script?

14 Oct 2019, 18:44

I have a script I've been customizing (below), and am trying to GroupAdd multiple web browsers into a group so that a few text auto-expands only apply to those browsers. I'm finding, however, that GroupAdd only seems to work at the top of the script. As soon as the script reaches one of the keyboard shortcuts, GroupAdd doesn't work below that.

Am I missing something or doing something wrong? Or can GroupAdd only be used at the beginning of scripts only?

https://www.autohotkey.com/docs/scripts/EasyWindowDrag_(KDE).htm
gregster
Posts: 3606
Joined: 30 Sep 2013, 06:48

Re: Can GroupAdd only be used at the beginning of a script?

15 Oct 2019, 00:06

That's a general concept, it's not GroupAdd-specific.

In general, code must be reachable to be able to get executed at some point. The top of the script (aka the auto-execute section) is a good place to make general assigmnents and other stuff:
https://www.autohotkey.com/docs/Scripts.htm#auto wrote:After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section.
That means, at the first hotstring/hotkey definition, this auto-execute section is done (among other cases, see above). Thus, either do these GroupAdds at the beginning or make sure that they get executed soon enough to be of use (via gosub, SetTimer, in a hotkey defintion before you actually use that group etc.). If all the window titles for the group are known at script start, just put them at the top of your script.

But if you put stray code between hotkey/hotstring defintions, it will be unreachable...

Code: Select all

msgbox This gets auto-executed at script start!
gosub somelabel
;end of the auto-execute section
1::ExitApp

msgbox	; this code is unreachable

2::tooltip, Hello world!

somelabel:
msgbox This works, too!
return	; jumps back
User avatar
Coldblackice
Posts: 19
Joined: 13 Nov 2013, 14:39

Re: Can GroupAdd only be used at the beginning of a script?

15 Oct 2019, 18:03

Ah, got it. That makes sense. Thanks very much for the explanation + example!

Return to “Ask For Help”

Who is online

Users browsing this forum: badnecros, Bing [Bot], malcev and 220 guests