Hotkey and Button that should do the same but react differently

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Joab
Posts: 3
Joined: 23 May 2017, 06:51

Hotkey and Button that should do the same but react differently

23 May 2017, 07:03

Hi!

I have a weird problem..

I have the following code to show the problem. If you run this, you get an edit field with a button. If you press the button, you get a MsgBox with the text that is in the edit box. All is good up until this point.

If you press ^t; you should get the same result. However, it seems like the program just skips over the Gui, Submit when using the hotkey. When you press ^t BEFORE you have ever hit the button, it shows an empty MsgBox. When you press the Button and after that you press ^t, it shows the text that is inside the edit. When you change the text in the editbox however, ^t will still just show the old text instead of the new text. That is until you press the button again.

Am I wrong in thinking ^t and the button should do exactly the same? And, more importantly, how do I get my code to Gui, Submit using the hotkey instead of the button?

Thanks so much for your help!

Joab

Code: Select all

Gui, New, , TEST
Gui, Add, Edit, vtestfield, tekstdsfssfgdhghgdgdghdhgdhdfgh
Gui, Add, button, gaction, testbutton
Gui, show, AutoSize

^t::
action:
gui, submit, Nohide
MsgBox % testfield
return

GuiClose:
ExitApp
Joab
Posts: 3
Joined: 23 May 2017, 06:51

Re: Hotkey and Button that should do the same but react differently

23 May 2017, 07:30

I found a solution!

It turns out that by removing the first line (Gui,New,, TEST) the problem disappears. So it probably has something to do with which GUI is active; and pressing a button on a GUI will make it obvious which GUI is the target, whilst using a hotkey requires a GUI to be specified. I don't know how I specify a GUI, but at this point I don't need to either.


Joab
Joab
Posts: 3
Joined: 23 May 2017, 06:51

Re: Hotkey and Button that should do the same but react differently

23 May 2017, 07:31

I found a solution!

It turns out that by removing the first line (Gui,New,, TEST) the problem disappears. So it probably has something to do with which GUI is active; and pressing a button on a GUI will make it obvious which GUI is the target, whilst using a hotkey requires a GUI to be specified. I don't know how I specify a GUI, but at this point I don't need to either.


Joab

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Archimede, Bing [Bot], RSable, Spikea and 319 guests