 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
cornell2
Joined: 18 Mar 2005 Posts: 166
|
Posted: Sat Apr 23, 2005 10:18 pm Post subject: Novice GUI Question |
|
|
OK - Hopefully someone here will take mercy on me and answer this simple one. I am otherwise pretty adept at AHK, but only now am diving into the GUI functions.
I simply want the GUI combo box to sumbit upon enter (no OK button), and I cannot seem to figure out how! See the sample script below. (yes, I KNOW the GUIEnter is wrong - i am just illustrating what I want it to do)
-----------------------------
| Code: | Gui, Add, COmbobox, x136 y38 w79 h133 vMyComb, First | Second | Third || Fourth | Fifth
Gui, Show, x270 y110 h377 w477, Choose One
Gui, Submit, NoHide
Return
GuiEnter:
MsgBox You entered the following:`n%MyComb%`n
return
GuiClose:
GuiEscape:
ExitApp |
-------------------
So what is the obvious piece I am missing?
Thanks! |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Sat Apr 23, 2005 10:31 pm Post subject: |
|
|
This seems to work-
| Code: | Gui, Add, COmbobox, x136 y38 w79 h133 vMyComb gSubmit, First | Second | Third || Fourth | Fifth
Gui, Show, x270 y110 h377 w477, Choose One
Return
Submit:
Gui, Submit, NoHide
MsgBox You entered the following:`n%MyComb%`n
return
GuiClose:
GuiEscape:
ExitApp |
|
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2421
|
Posted: Sat Apr 23, 2005 10:36 pm Post subject: |
|
|
| Code: | Gui, Add, COmbobox, x136 y38 w79 h133 vMyComb gGuiEnter, First | Second | Third || Fourth | Fifth
Gui, Show, x270 y110 h377 w477, Choose One
Gui, Submit, NoHide
Return
GuiEnter:
Gui, Submit, NoHide
if A_GuiControlEvent = Normal
MsgBox You entered the following:`n%MyComb%`n
return
GuiClose:
GuiEscape:
ExitApp |
|
|
| Back to top |
|
 |
cornell2
Joined: 18 Mar 2005 Posts: 166
|
Posted: Sat Apr 23, 2005 10:50 pm Post subject: |
|
|
Doesn't work for me!!!!
(it actually displays the message box every time I use the arrow in the combo box. Not enter. |
|
| Back to top |
|
 |
cornell2
Joined: 18 Mar 2005 Posts: 166
|
Posted: Sat Apr 23, 2005 10:52 pm Post subject: |
|
|
Same with this script! I get the msgbox - not with ENter ... but every time I scroll with an up/down arrow.
????? |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Sat Apr 23, 2005 10:53 pm Post subject: |
|
|
| Sorry, I misread the question |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10474
|
Posted: Sat Apr 23, 2005 11:38 pm Post subject: Re: Novice GUI Question |
|
|
| cornell2 wrote: | | I simply want the GUI combo box to sumbit upon enter (no OK button) | It seems that you can have a hidden default button as a trick to make this work:
Gui, Add, COmbobox, x136 y38 w79 h133 vMyComb, First | Second | Third || Fourth | Fifth
Gui, Add, Button, Default Hidden, OK
Gui, Show, x270 y110 h377 w477, Choose One
Gui, Submit, NoHide
Return
ButtonOK:
MsgBox You entered the following:`n%MyComb%`n
return
GuiClose:
GuiEscape:
ExitApp |
|
| Back to top |
|
 |
cornell2
Joined: 18 Mar 2005 Posts: 166
|
Posted: Sat Apr 23, 2005 11:45 pm Post subject: Re: Novice GUI Question |
|
|
This worked like a charm!!
(a shame that one has to used a trick like this, for such a common use) .. I hope this trick does not cause any complications later, as I try to make my form more robust.
Thanks a lot !!!! |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2421
|
Posted: Sun Apr 24, 2005 4:07 am Post subject: |
|
|
Sorry, I misread the question too . Here's another method that might work ok if you need to set another button as the default button instead. | Code: | WinTitle = Choose One
Gui, Add, ComboBox, x136 y38 w79 h133 vMyComb, First | Second | Third || Fourth | Fifth
Gui, Show, x270 y110 h377 w477, %WinTitle%
Gui, Submit, NoHide
SetTimer, listenter, 250
Return
listenter:
WinGetActiveTitle, ActWin
if ActWin = %WinTitle%
{
ControlGetFocus, ControlWithFocus, %WinTitle%
if ControlWithFocus = Edit1
{
KeyWait, Enter, DT0.10
if ErrorLevel = 0
{
Gui, Submit, NoHide
SetTimer, listenter, Off
MsgBox You entered the following:`n%MyComb%`n
SetTimer, listenter, 250
}
}
}
Return
GuiClose:
GuiEscape:
ExitApp |
The method that Chris suggested is neater and more efficient though . |
|
| Back to top |
|
 |
cornell2
Joined: 18 Mar 2005 Posts: 166
|
Posted: Mon Apr 25, 2005 5:21 pm Post subject: A similar GUI Question |
|
|
All these solutions seem uncommonly kludgy, no? (pointing out the limitations of AHK/GUI ... not in the solutions). I mean someone hitting enter at any point in the form is as important an event to capture as escape or close (pgup/down would be good too). Having so many lines of code, subject to such complexities of timing etc seems too complex.
Anyway I have another question - the answer might benefit others too. Another fundamental issue:
1. I have some "parent" script, that is mean to, at certain times, gosub to my GUI form and get some data (so the gui-form should be isolated and consolidated in one subroutine. ie
| Code: | ; -----
; beginning of script
..
..
gosub form_input_routine
..
; do other things when returned.
msgbox, I have returned
..
.. ----
..
form_input_routine:
gui, add, ... whatever
gui, add, ... whatever
gui, add, ... whatever
gui, show
gui, submit
return
guiclose:
guiescape:
return |
My problem is that this displays the form but the returns to the main script before the user is finished with the form. How do I make my gui-forms work such that they do not continue processing the script until the form is complete.
Normally I would apologize in advance, saying how simple this solution must be, and that I must have missed some obvious parameter. But after the thread here about simply capturing the enter key, my expectations for a simple answer are lowered
Thanks! |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4065 Location: Pittsburgh
|
Posted: Mon Apr 25, 2005 8:27 pm Post subject: |
|
|
| Quote: | | …hitting enter at any point in the form is as important an event to capture as escape or close... | But multi-line edit fields need to start new lines, combo boxes could select the highlighted entry at Enter, etc., so you need different actions or no action at all. You cannot satisfy all desires. A hidden or visible default button is the most universal solution. It captures Enter when you want to, and you assign a function you need. The code is short and self explanatory. |
|
| Back to top |
|
 |
cornell2
Joined: 18 Mar 2005 Posts: 166
|
Posted: Mon Apr 25, 2005 8:44 pm Post subject: |
|
|
Good point about the multiline edit fields.
I will tryu the hidden default button (again) .. I agree the code is short but not always self-explanatory. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10474
|
|
| Back to top |
|
 |
cornell2
Joined: 18 Mar 2005 Posts: 166
|
Posted: Tue Apr 26, 2005 3:36 am Post subject: |
|
|
LOL - this is my other posting on the subject! (see the first part of this thread to see why I posted new).
btw - all the solutions have worked like a charm
Thanks all! |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10474
|
Posted: Tue Apr 26, 2005 3:55 am Post subject: |
|
|
| Quote: | | LOL - this is my other posting on the subject! | I knew that; I just didn't want anyone to waste their time answering your other questions above when they had already been answered in the other thread.  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|