Selecting/Prioritizing a GUI button

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hidefguy
Posts: 57
Joined: 11 Apr 2017, 20:42

Selecting/Prioritizing a GUI button

12 Dec 2018, 09:43

After executing this script, I still need to tab my way to the OK button. I'm trying to figure out how to prioritize the button, so that once GUI appears, all you do is hit enter on keyboard. Kind of like most windows GUI's.

Code: Select all

Gui, Add, Button, x40 y60 w80 h30 , OK
Gui, Add, Button, x180 y60 w80 h30 , Cancel
Gui, Show, x800 y500 h150 w300, INPUT 
Return
ButtonCancel:
GuiEscape:
Gui, Destroy
Enter:
NumpadEnter:
ControlGetFocus, myFocus, INPUT, Button1
if (myFocus = "Button1")
{
    Goto, ButtonOK
}
else
if (myFocus = "Edit2" or "Button2")
{
    Gui, Destroy
    Exit
}
ButtonOK:
Gui, Submit
Gui, Destroy
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Selecting/Prioritizing a GUI button

12 Dec 2018, 09:55

Change first line to make OK-button respond to {Enter}:

Code: Select all

Gui, Add, Button, x40 y60 w80 h30 Default, OK
I hope that helps.
hidefguy
Posts: 57
Joined: 11 Apr 2017, 20:42

Re: Selecting/Prioritizing a GUI button

12 Dec 2018, 10:07

That worked great wolf_II. You're the best ;)
garry
Posts: 3768
Joined: 22 Dec 2013, 12:50

Re: Selecting/Prioritizing a GUI button

12 Dec 2018, 11:11

@wolf_II , thank you
when start GUI , firsttime is OK-button selected , later then is always Calc activ
I tried with Hotkey

Code: Select all

Gui, Add, Button, x40 y60 w80 h30  gCalc1 , Calc
Gui, Add, Button, x180 y60 w80 h30 gOK1 default, OK
Gui, Show, x800 y500 h150 w300, INPUT 
;Hotkey,Enter,ok1,ON    ;- <<  goto OK1 when use Enter
Return
guiclose:
exitapp
OK1:
msgbox,OK
return
calc1:
run,calc
return
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Selecting/Prioritizing a GUI button

13 Dec 2018, 06:08

@garry: I don't really follow. I tried your script, and all seems to work for me.
garry
Posts: 3768
Joined: 22 Dec 2013, 12:50

Re: Selecting/Prioritizing a GUI button

14 Dec 2018, 03:27

@wolf_II , when firsttime use 'enter' > OK , then > calc is selected
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Selecting/Prioritizing a GUI button

14 Dec 2018, 05:05

@garry Ahh, thx, now I see. :wave:

Maybe, the order in which we add controls matter. I mean, the order matters for sure, but in more than one way.
Suppose we simply swap the first two lines in your script, then the GUI looks identical.
The OK button with his coords and Default option is first, the non-default button "Calc" is added later, and gets a later position in the tab-order of controls.

With the Default button in second position, we see what you say, with the Default button in first position, we would not. (in one of my tests: run script - keep hitting enter - observation: no Calculator)

On the other hand - suppose we remove the default option - I can start the script, manually mouse over a button (Test1 click OK, Test2 click Calc)
I then find: having hit a button manually, sort of preselects the Button for later, meaning I can force a cycle of msgBoxes, or a cycle of calculators. And I can jump from one cycle to the next.

Hmmm, I have presently no explanation regarding priority of [ Last-used-button vs. Default-button ]
but I could recreate the issue. Thanks for pointing to it. :thumbup:
garry
Posts: 3768
Joined: 22 Dec 2013, 12:50

Re: Selecting/Prioritizing a GUI button

14 Dec 2018, 10:22

@wolf_II , thank you

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jameswrightesq, nacken012 and 208 guests