Multi GUIs in same script and hotkeys? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Multi GUIs in same script and hotkeys?

Post by Krd » 13 May 2022, 10:52

Hello again.

I really don't get how to use GUIs as it makes me more confused before I try to learn.

I have several big scripts which I want to add GUIs instead of MsgBox as GUIs are better to adapt to what I want.

Some times I want a GUI in middle of a script that consists of 1600 lins of code which again consists of several functions and objects.

By adding anything in start of script and GUI after it gives many warnings. See line 5 under.

And I really don't get that how can I add GUIs to my scripts to show up without a hotkey.

Any one have time to make this under to work by existing in same file? So I take the learning from there :) :crazy:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
::FTW::Free the world

Gui, Add, Text,, Enter first text Submit:
Gui, Add, Edit, vAssociatedVar
Gui, Add, Button,, Submit
F12::Gui, Show
Return

ButtonSubmit:
Gui, Submit, NoHide
MsgBox, Content of first text: %AssociatedVar%
Return



Gui, Add, Text,, Enter second text Submit:
Gui, Add, Edit, vAssociatedVar
Gui, Add, Button,, Submit2
F11:: Gui, Show
Return

ButtonSubmit2:
Gui, Submit, NoHide
MsgBox, Content of second text: %AssociatedVar%
Return 

User avatar
mikeyww
Posts: 27107
Joined: 09 Sep 2014, 18:38

Re: Multi GUIs in same script and hotkeys?  Topic is solved

Post by mikeyww » 13 May 2022, 13:14

Code: Select all

Gui, Add, Text,, Enter first text Submit:
Gui, Add, Edit, vAssociatedVar1
Gui, Add, Button,, Submit
Gui, 2:New
Gui, Add, Text,, Enter second text Submit:
Gui, Add, Edit, vAssociatedVar2
Gui, Add, Button,, Submit

F11::Gui, Show, x100 y100
F12::Gui, 2:Show, x300 y300
::FTW::Free the world

ButtonSubmit:
Gui, Submit
MsgBox, Content of first text: %AssociatedVar1%
Return

2ButtonSubmit:
Gui, 2:Submit
MsgBox, Content of second text: %AssociatedVar2%
Return

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Multi GUIs in same script and hotkeys?

Post by Krd » 14 May 2022, 16:09

@mikeyww

Thank you so much. That was clear!

I a noob think this is so wierd compared to rest of basic autohotkey. No where I could find anything as you describe, in docs I found it is good to use New for mutliple GUIs, but where and how to use it...? :S In videos people show them for games or Pop up messages at same time...

Im sure many nuebs will find this helpfull.

Why do controlls go crazy if they are not the first part of code? I would love them to be put on brackets and use them inside functions. Is this the same in V2?

Can I add GUIs in its own script and call them from another script but put the labels in running scripts? Not asking to make scripts for me just so the noob knows how things work.

Now I get why Boiler said that GUIs can be used witout a hotkey, as shown under. ButI couldn't make it work if the GUI was the first thing to start the script with.

Mikeyww, what I am trying to do under, is it again a noob idea that doesn't work this way?

Code: Select all

F1::
MsgBox, After this you will see a GUI
Sleep, 500
Gui, 2:Show, 
Sleep, 500
Msgbox, GUI didn't wait for input beofre I showed up... Im not done and I don't know how to make GUI do it¨s part first before jumping to me, I want ot see the content of input first.... Ask Mikeyww :)
return

User avatar
mikeyww
Posts: 27107
Joined: 09 Sep 2014, 18:38

Re: Multi GUIs in same script and hotkeys?

Post by mikeyww » 14 May 2022, 17:07

I admit that this takes a bit of practice. The documentation for Gui, New could use improvements, but you can read that section to learn something.

Read about auto-execute, which explains why your "running code" needs to be put at the top of the script. Unlabeled code following Return is unreachable and will never execute, because that is how the Return command works: it returns from a subroutine to which execution had previously jumped.

Although I think of a script as a file of instructions (often containing labeled subroutines), some people use the term differently, and I do not know how you are using it. I also do not know how you are using the term "label", which has a specific meaning in AHK (and probably coding in general). In any case, you can use variables when you build your GUI, whether that happens in auto-exec or within a subroutine or function.

The Gui, Show command itself does not pause or wait for something to happen; instead, the script proceeds. You can, however, write your script so that a GUI button triggers an action when it is activated. To have your MsgBox appear after your button is pressed, you would put the MsgBox into the 2ButtonSubmit subroutine. I have provided an example of that in my script.

A noob has fewer than 50 posts, :D so you are now officially a novice and can do more advanced things. With your new status, you are able to read the docs, write fancy scripts, use the right terminology, and teach others. :happybday:

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Multi GUIs in same script and hotkeys?

Post by Krd » 16 May 2022, 00:57

Many thanks mikeyww! Much appreciated.

The thing is that I do not spend much time learning as I work more and make things happen fast.

But now I have moved focus to learn more about this great tool whenever i have some time and hopefully be able to help others as you do. At least maybe my pro questions do help someone :)

:bravo:

Post Reply

Return to “Ask for Help (v1)”