CoderDude Posted August 21, 2006 Share Posted August 21, 2006 Newbie here, so possibly stupid question...: Can almost do what I want to with InputBox, but trying to do the same with GUICtrlCreateInput()...: I want to create a GUI with an input field. The user can only enter something and press enter, or kill the window with the little x in the upper right corner. I don't want an 'Ok' button, I want 'Enter' to be all the user has to do. Here is what I have: #include <GuiConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $mainwindow = GUICreate("Title Goes Here", 400, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GuiCtrlCreateLabel("Please Enter:", 150, 20) $card=GuiCtrlCreateInput("", 130, 50, 130, 20) GUICtrlSetOnEvent($card, "ScanComplete") GUISetState(@SW_SHOW) While 1 Sleep(1000) ; Idle around WEnd Func ScanComplete() MsgBox(0, "GUI Event", "It works!") EndFunc Func CLOSEClicked() MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...") Exit EndFunc The problem is, ScanComplete is never called on any keys, Enter, TAB, nothing makes it go. If you click on the thing to minimize the window, then it is called, but I think only if the input field changed. How do I make it terminate on 'Enter'? Thanks.... Link to comment Share on other sites More sharing options...
taurus905 Posted August 21, 2006 Share Posted August 21, 2006 (edited) CoderDude, First off, welcome to the forum. Second, when you post your code, please use [ code] and [ /code] tags (without the spaces) to make your scripts more readable for other users. And third, I'm sure this is not the best answer or solution to your question, but maybe it will prompt a response from more knowledgeable users. taurus905#include <GuiConstants.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1); Change to OnEvent mode $mainwindow = GUICreate("Title Goes Here", 400, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlCreateLabel("Please Enter:", 150, 20) $card = GUICtrlCreateInput("", 130, 50, 130, 20) ;GUICtrlSetOnEvent($card, "ScanComplete") GUISetState(@SW_SHOW) While 1 ;Sleep(1000); Idle around If _IsPressed("0D") Then ScanComplete() WEnd Func ScanComplete() MsgBox(0, "GUI Event", "It works!") EndFunc ;==>ScanComplete Func CLOSEClicked() MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...") Exit EndFunc ;==>CLOSEClicked Edited August 21, 2006 by taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
BigDod Posted August 21, 2006 Share Posted August 21, 2006 Another example #include <GUIConstants.au3> $Form1 = GUICreate("AForm1", 633, 447, 193, 115) $Input1 = GUICtrlCreateInput("", 64, 48, 385, 21) $Button1 = GUICtrlCreateButton("AButton1", 64, 88, 49, 25, $BS_DEFPUSHBUTTON) GUICtrlSetState(-1, $GUI_HIDE) GUISetState(@SW_SHOW) While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE ExitLoop Case $Msg = $Button1 MsgBox(4096, "input", GUICtrlRead($Input1)) ExitLoop Case Else EndSelect WEnd Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
CoderDude Posted August 22, 2006 Author Share Posted August 22, 2006 Well that is sneaky.... So I guess the answer is that GUICtrlCreateInput doesn't terminate with 'Enter', but you can cheat with a hidden $BS_DEFPUSHBUTTON button. Thanks guys! Event mode version below. It works great. Note that this does not work if you use GUISetOnEvent on the button, it has to be GUICtrlSetOnEvent... Not sure what the difference is, the descriptions seem pretty identical...(?) #include <GUIConstants.au3> Opt("GUIOnEventMode", 1); Change to OnEvent mode $mainwindow = GUICreate("Title Goes Here", 400, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GuiCtrlCreateLabel("Please Enter:", 150, 20) $card=GuiCtrlCreateInput("", 130, 50, 130, 20) $EnterButton = GUICtrlCreateButton("AButton1", 100, 70, 49, 25, $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent($EnterButton,"ScanComplete") GUICtrlSetState(-1, $GUI_HIDE) GUISetState(@SW_SHOW) While 1 Sleep(1000); Idle around WEnd Func ScanComplete() MsgBox(0, "GUI Event", "It works!") EndFunc Func CLOSEClicked() MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...") Exit EndFunc Link to comment Share on other sites More sharing options...
taurus905 Posted August 22, 2006 Share Posted August 22, 2006 Another example #include <GUIConstants.au3> $Form1 = GUICreate("AForm1", 633, 447, 193, 115) $Input1 = GUICtrlCreateInput("", 64, 48, 385, 21) $Button1 = GUICtrlCreateButton("AButton1", 64, 88, 49, 25, $BS_DEFPUSHBUTTON) GUICtrlSetState(-1, $GUI_HIDE) GUISetState(@SW_SHOW) While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE ExitLoop Case $Msg = $Button1 MsgBox(4096, "input", GUICtrlRead($Input1)) ExitLoop Case Else EndSelect WEndBigDod, Nice use of $BS_DEFPUSHBUTTON I saw that in the help file, but was not aware that it could be used that way. taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now