scriptjunkie Posted October 11, 2008 Share Posted October 11, 2008 Here is my example script: #include <GUIConstants.au3> #include <GUIComboBox.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 351, 59, 303, 219) $Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25) $Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUISetOnEvent($GUI_EVENT_CLOSE, "_quit") GUICtrlSetOnEvent($Button1, "_submitbtn") GUICtrlSetOnEvent($Combo1, "_combobox") While 1 Sleep(1000) WEnd Func _quit() Exit EndFunc Func _submitbtn() $var = GUICtrlRead($Combo1) _GUICtrlComboBox_AddString($Combo1,$var) EndFunc Func _combobox() $var = GUICtrlRead($Combo1) msgbox(0,0,$var) EndFunc I tried searching the forum for how to get the event for when pressing enter. I could only find topics using a hotkey. I'd like to have a way to type into the combo box, and press enter then run function _submitbtn(). Is this possible? Link to comment Share on other sites More sharing options...
Andreik Posted October 11, 2008 Share Posted October 11, 2008 (edited) Here is my example script: #include <GUIConstants.au3> #include <GUIComboBox.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 351, 59, 303, 219) $Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25) $Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUISetOnEvent($GUI_EVENT_CLOSE, "_quit") GUICtrlSetOnEvent($Button1, "_submitbtn") GUICtrlSetOnEvent($Combo1, "_combobox") While 1 Sleep(1000) WEnd Func _quit() Exit EndFunc Func _submitbtn() $var = GUICtrlRead($Combo1) _GUICtrlComboBox_AddString($Combo1,$var) EndFunc Func _combobox() $var = GUICtrlRead($Combo1) msgbox(0,0,$var) EndFunc I tried searching the forum for how to get the event for when pressing enter. I could only find topics using a hotkey. I'd like to have a way to type into the combo box, and press enter then run function _submitbtn(). Is this possible? I don't understand very good. Like this? expandcollapse popup#include <GUIConstants.au3> #include <GUIComboBox.au3> #include <Misc.au3> #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 351, 59, 303, 219) $Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25) $Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### AdlibEnable("_submitbtn",100) While 1 $MSG = GUIGetMsg() Switch $MSG Case $Combo1 Call("_combobox") Case $GUI_EVENT_CLOSE Call("_quit") EndSwitch Sleep(20) WEnd Func _quit() AdlibDisable() Exit EndFunc Func _submitbtn() If _IsPressed('0D') Then $var = GUICtrlRead($Combo1) _GUICtrlComboBox_AddString($Combo1,$var) EndIf EndFunc Func _combobox() $var = GUICtrlRead($Combo1) msgbox(0,0,$var) EndFunc Edited October 11, 2008 by Andreik Link to comment Share on other sites More sharing options...
oMBRa Posted October 11, 2008 Share Posted October 11, 2008 search in the help for _IsPressed Link to comment Share on other sites More sharing options...
Andreik Posted October 11, 2008 Share Posted October 11, 2008 Or like this without Adlib. expandcollapse popup#include <GUIConstants.au3> #include <GUIComboBox.au3> #include <Misc.au3> #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 351, 59, 303, 219) $Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25) $Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0) GUISetState(@SW_SHOW) Global $LAST = "" #EndRegion ### END Koda GUI section ### $DLL = DllOpen('user32.dll') While 1 $MSG = GUIGetMsg() Switch $MSG Case $Combo1 Call("_combobox") Case $GUI_EVENT_CLOSE Call("_quit") EndSwitch If _IsPressed('0D',$DLL) And $LAST <> GUICtrlRead($Combo1) Then Call("_submitbtn") EndIf Sleep(20) WEnd Func _quit() DllClose($DLL) Exit EndFunc Func _submitbtn() $LAST = GUICtrlRead($Combo1) _GUICtrlComboBox_AddString($Combo1,$LAST) EndFunc Func _combobox() $var = GUICtrlRead($Combo1) msgbox(0,0,$var) EndFunc Link to comment Share on other sites More sharing options...
scriptjunkie Posted October 11, 2008 Author Share Posted October 11, 2008 (edited) Thanks for the idea with ispressed. But, I have tried this. It doesn't work with sleep(1000) very well. If I hold down enter then it run the function multiple times. ispressed, and hotkey the only options? I guess I could do this with a shorter sleep time. #include <GUIConstants.au3> #include <GUIComboBox.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 351, 59, 303, 219) $Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25) $Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUISetOnEvent($GUI_EVENT_CLOSE, "_quit") GUICtrlSetOnEvent($Button1, "_submitbtn") GUICtrlSetOnEvent($Combo1, "_combobox") $dll = DllOpen("user32.dll") While 1 Sleep(200) If _IsPressed("0D", $dll) Then _submitbtn() WEnd Func _quit() DllClose($dll) Exit EndFunc Func _submitbtn() $var = GUICtrlRead($Combo1) _GUICtrlComboBox_AddString($Combo1,$var) EndFunc Func _combobox() $var = GUICtrlRead($Combo1) msgbox(0,0,$var) EndFunc Edited October 11, 2008 by scriptjunkie Link to comment Share on other sites More sharing options...
Andreik Posted October 11, 2008 Share Posted October 11, 2008 Thanks for the idea with ispressed. But, I have tried this. It doesn't work with sleep(1000) very well. If I hold down enter then it run the function multiple times. ispressed, and hotkey the only options? I guess I could do this with a shorter sleep time. #include <GUIConstants.au3> #include <GUIComboBox.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 351, 59, 303, 219) $Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25) $Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUISetOnEvent($GUI_EVENT_CLOSE, "_quit") GUICtrlSetOnEvent($Button1, "_submitbtn") GUICtrlSetOnEvent($Combo1, "_combobox") $dll = DllOpen("user32.dll") While 1 Sleep(200) If _IsPressed("0D", $dll) Then _submitbtn() WEnd Func _quit() DllClose($dll) Exit EndFunc Func _submitbtn() $var = GUICtrlRead($Combo1) _GUICtrlComboBox_AddString($Combo1,$var) EndFunc Func _combobox() $var = GUICtrlRead($Combo1) msgbox(0,0,$var) EndFunc Look example from post #4. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted October 11, 2008 Share Posted October 11, 2008 I believe it would fit better to use accelerators in this case. #include <GUIConstantsEx.au3>;If you're using 3.2.10.0 or newer it's Ex that should be used. #include <GUIComboBox.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form2", 351, 59, 303, 219) $Combo1 = GUICtrlCreateCombo("", 24, 16, 185, 25) $Button1 = GUICtrlCreateButton("Submit", 232, 15, 89, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUISetOnEvent($GUI_EVENT_CLOSE, "_quit") GUICtrlSetOnEvent($Button1, "_submitbtn") GUICtrlSetOnEvent($Combo1, "_combobox") Dim $AccelKeys[1][2]=[["{Enter}", $Button1]] GUISetAccelerators($AccelKeys) While 1 Sleep(1000) WEnd Func _quit() Exit EndFunc Func _submitbtn() $var = GUICtrlRead($Combo1) _GUICtrlComboBox_AddString($Combo1,$var) EndFunc Func _combobox() $var = GUICtrlRead($Combo1) msgbox(0,0,$var) EndFunc .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
scriptjunkie Posted October 14, 2008 Author Share Posted October 14, 2008 Thank you AdmiralAlkex. I did not know about this option because I was still on 3.2.10, but this worked perfectly. =) 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