Is it possible to insert a command in here, that when I tab to GUI Cancel button and press Enter, the script returns and not continue? Same way it does when pressing Esc or clicking Cancel
Gui, Add, Text, x12 y20 w80 h30, Date
Gui, Add, Edit, x112 y20 w80 h20 vDate,
Gui, Add, Button, x40 y270 w80 h30 , OK
Gui, Add, Button, x180 y270 w80 h30 , Cancel
Gui, Show, x800 y400 h325 w300, INPUT
Return
ButtonCancel:
GuiEscape:
Gui, Destroy
Return
ButtonOK:
Enter::
NumpadEnter::
Gui, Submit
Gui, Destroy
Tab to Cancel button on GUI continues script with Enter key
Tab to Cancel button on GUI continues script with Enter key
Last edited by hidefguy on 14 Mar 2018, 22:35, edited 3 times in total.
Re: Tab to Cancel on GUI continues script
Gui, Add, Button, x180 y270 w80 h30 gButtonCancel, Cancel
Re: Tab to Cancel on GUI continues script
Tried this. Script still continues
Gui, Add, Text, x12 y20 w80 h30, Date
Gui, Add, Edit, x112 y20 w80 h20 vDate,
Gui, Add, Button, x40 y270 w80 h30 , OK
Gui, Add, Button, x180 y270 w80 h30 , Cancel
Gui, Add, Button, x180 y270 w80 h30 gButtonCancel, Cancel
Gui, Show, x800 y400 h325 w300, INPUT
Return
ButtonCancel:
gButtonCancel:
GuiEscape:
Gui, Destroy
Return
ButtonOK:
Enter::
NumpadEnter::
Gui, Submit
Gui, Destroy
Gui, Add, Text, x12 y20 w80 h30, Date
Gui, Add, Edit, x112 y20 w80 h20 vDate,
Gui, Add, Button, x40 y270 w80 h30 , OK
Gui, Add, Button, x180 y270 w80 h30 , Cancel
Gui, Add, Button, x180 y270 w80 h30 gButtonCancel, Cancel
Gui, Show, x800 y400 h325 w300, INPUT
Return
ButtonCancel:
gButtonCancel:
GuiEscape:
Gui, Destroy
Return
ButtonOK:
Enter::
NumpadEnter::
Gui, Submit
Gui, Destroy
Re: Tab to Cancel on GUI continues script
Searched this forum into the abyss, and still can’t figure this out. Like any Windows program, I want the capability to Tab my way to Cancel button on input box and execute the cancel button by pressing Enter.
Is this not a trivial task in AHK?
Is this not a trivial task in AHK?
Re: Tab to Cancel on GUI continues script
Code: Select all
ButtonCancel:
GuiEscape:
Gui, Destroy
ExitApp ; Gui applications are persistent and need ExitApp instead of Return/Exit
Re: Tab to Cancel on GUI continues script
TY, but this doesn't relate to using the enter key when tabbing over the Cancel button. This exits the entire script. AHK allows for only one Enter:: command which I have reserved to start the remaining script. The goal is to reference the enter key to cancel Gui only when tabbed over the cancel button.
- divanebaba
- Posts: 816
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Tab to Cancel on GUI continues script
Hi.
If your enter-key is remapped or used by a hotstring, you can add a query to find active focus. If active focus is your cancel-button, you can do your stuff.
Look for ControlGetFocus.
Like code below:
If your enter-key is remapped or used by a hotstring, you can add a query to find active focus. If active focus is your cancel-button, you can do your stuff.
Look for ControlGetFocus.
Like code below:
Code: Select all
Enter::
ControlGetFocus, myFocus, myWindowTitle
if (myFocus = "Button7")
...
else
...
Einfach nur ein toller Typ.
Re: Tab to Cancel on GUI continues script
Tried this but get else not recognized error
Gui, Add, Text, x12 y20 w80 h30, Date
Gui, Add, Edit, x112 y20 w80 h20 vDate,
Gui, Add, Button, x40 y270 w80 h30 , OK
Gui, Add, Button, x180 y270 w80 h30 , Cancel
Gui, Show, x800 y400 h325 w300, INPUT
Return
ButtonCancel:
GuiEscape:
Gui, Destroy
Return
Enter::
NumpadEnter::
ControlGetFocus, myFocus, INPUT
if (myFocus = "ButtonCancel")
else
ButtonOK:
Gui, Submit
Gui, Destroy
Gui, Add, Text, x12 y20 w80 h30, Date
Gui, Add, Edit, x112 y20 w80 h20 vDate,
Gui, Add, Button, x40 y270 w80 h30 , OK
Gui, Add, Button, x180 y270 w80 h30 , Cancel
Gui, Show, x800 y400 h325 w300, INPUT
Return
ButtonCancel:
GuiEscape:
Gui, Destroy
Return
Enter::
NumpadEnter::
ControlGetFocus, myFocus, INPUT
if (myFocus = "ButtonCancel")
else
ButtonOK:
Gui, Submit
Gui, Destroy
- divanebaba
- Posts: 816
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Tab to Cancel on GUI continues script
Hi.
Try to find the classNN of your CancelButton with WindowSpy or ACC-Viewer.
It should be "Button2" or another number, depending on the amount of buttons or viewer, you use.
Try first WindowSpy. If this fails, try ACC-Viewer.
EDIT: A little fault in your code. Replace with following:
Try to find the classNN of your CancelButton with WindowSpy or ACC-Viewer.
It should be "Button2" or another number, depending on the amount of buttons or viewer, you use.
Try first WindowSpy. If this fails, try ACC-Viewer.
EDIT: A little fault in your code. Replace with following:
Code: Select all
...
if (myFocus = "Button2")
msgbox Yes, it is Button2
else
msgbox No, it was not Button2
...
Einfach nur ein toller Typ.
Re: Tab to Cancel on GUI continues script
divanebaba
This variation of your snippet worked well. Tabbing/pressing Enter key to Button 2 (Cancel or No), destroys and returns GUI, but with Enter key at Button 1 (OK or Yes), or pressing Enter anytime/anywhere it will generate another GUI asking to continue, or not. This way the script doesn't run away. Alternately, the Esc key can be used to exit any GUI, with command GuiEscape:
I'm sure it will be useful to someone in the future. Thank you all for your help.
This variation of your snippet worked well. Tabbing/pressing Enter key to Button 2 (Cancel or No), destroys and returns GUI, but with Enter key at Button 1 (OK or Yes), or pressing Enter anytime/anywhere it will generate another GUI asking to continue, or not. This way the script doesn't run away. Alternately, the Esc key can be used to exit any GUI, with command GuiEscape:
I'm sure it will be useful to someone in the future. Thank you all for your help.
Code: Select all
Gui, Add, Text, x12 y20 w80 h30, Date
Gui, Add, Edit, x112 y20 w80 h20 vDate,
Gui, Add, Button, x40 y270 w80 h30 , OK
Gui, Add, Button, x180 y270 w80 h30 , Cancel
Gui, Show, x800 y400 h325 w300, INPUT
Return
ButtonCancel:
GuiEscape:
Gui, Destroy
Return
Enter::
NumpadEnter::
ControlGetFocus, myFocus1, INPUTS
if (myFocus1 = "Button1")
{
Goto, ButtonYes
}
else
if (myFocus1 = "Button2")
{
Gui, Destroy
Return
}
ControlGetFocus, myFocus2, CONTINUE
if (myFocus2 = "Button1")
{
Goto, ButtonYes
}
else
if (myFocus2 = "Button2")
{
Gui, Destroy
ExitApp
}
Gui, Submit
Gui, Destroy
Gui, Add, Text, x40 y30 w120 h50, Continue running script?
Gui, Add, Button, x40 y90 w80 h30 , Yes
Gui, Add, Button, x180 y90 w80 h30 , No
Gui, Show, x800 y500 h150 w300, CONTINUE
Return
Gui, Destroy
ButtonOK:
ButtonYes:
Gui, Submit
Gui, Destroy
sleep, 1000
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], VanVarden and 103 guests