Jabberwock Posted October 6, 2006 Posted October 6, 2006 I'm looking for a func i guess to detect the active input box and if a user presses enter it will execute, i realize that this can easily be done another way by setting a hotkey, or using _IsPressed and WinActive, but this won't work if you're using mutiple buttons with different functions, i tried searching the forums, but i really have no idea what this would be called, if anyone can point me to some thing some one has already made or post what they use I would appreciate it.
xcal Posted October 6, 2006 Posted October 6, 2006 GUICtrlSetState($some_button, $GUI_DEFBUTTON) That will cause pressing enter to fire $some_button. How To Ask Questions The Smart Way
Jabberwock Posted October 6, 2006 Author Posted October 6, 2006 well, this is a nice way if you've only got 1 button, but i mentioned i had multiple inputs with multiple buttons and the only way to get this to work is a func to detect the active input box and execute upon enter
Xenobiologist Posted October 6, 2006 Posted October 6, 2006 Hi, does this help? #include <GUIConstants.au3> HotKeySet("{Enter}", "_check") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("GUI", 633, 447, 193, 115) $Button1 = GUICtrlCreateButton("AButton1", 16, 16, 75, 25, 0) $Button2 = GUICtrlCreateButton("AButton2", 96, 16, 75, 25, 0) $Button3 = GUICtrlCreateButton("AButton3", 176, 16, 75, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 MsgBox(0, "Pressed", "1") Case $Button2 MsgBox(0, "Pressed", "2") Case $Button3 MsgBox(0, "Pressed", "3") EndSwitch WEnd Func _check() If WinActive("GUI") Then ControlClick("GUI", "", ControlGetFocus("GUI")) EndIf EndFunc ;==>_check So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Puckmeister Posted October 6, 2006 Posted October 6, 2006 i think this one will help you expandcollapse popup#include <GUIConstants.au3> ;define $hotkey = "{ENTER}" ;gui_starts here $hotkey_is_set = 0 $main_gui = GUICreate("Press Enter...", 220, 130) ; will create a dialog box that when displayed is centered $input1 = GUICtrlCreateInput ("Field 1", 10, 10, 200, 20) $input2 = GUICtrlCreateInput ("Field 2", 10, 40, 200, 20) $input3 = GUICtrlCreateInput ("Field 3", 10, 70, 200, 20) $input4 = GUICtrlCreateInput ("Field 4", 10, 100, 200, 20) ;show the gui GUISetState (@SW_SHOW) ;start the script While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop set_executekey() sleep (100) Wend ;de/activate hotkey Func set_executekey($mbox = 0) ;deactivate hotkey when window is active and msgbox is open ;(to prevent msgbox from open again when pressing enter while box is visible) If $mbox = 1 Then HotKeySet ($hotkey) $hotkey_is_set = 0 ;activate hotkey when window is active and hotkey isn`t set yet (checks $hotkey_is_set var) ElseIf WinActive ($main_gui) Then If $hotkey_is_set = 0 Then HotKeySet ($hotkey, "check_and_go") $hotkey_is_set = 1 EndIf ;deactivates hotkey if window isn`t active anymore and the hotkey was set before Else If $hotkey_is_set = 1 Then HotKeySet ($hotkey) EndIf EndIf EndFunc Func check_and_go() ;you can shorten this function if you use an array If ControlGetFocus($main_gui) = "Edit1" Then set_executekey(1) MsgBox (0, "1", GUICtrlRead ($input1)) ElseIf ControlGetFocus($main_gui) = "Edit2" Then set_executekey(1) MsgBox (0, "2", GUICtrlRead ($input2)) ElseIf ControlGetFocus($main_gui) = "Edit3" Then set_executekey(1) MsgBox (0, "3", GUICtrlRead ($input3)) ElseIf ControlGetFocus($main_gui) = "Edit4" Then set_executekey(1) MsgBox (0, "4", GUICtrlRead ($input4)) EndIf EndFunc greets, chris
Jabberwock Posted October 7, 2006 Author Posted October 7, 2006 input 1 has it's own button input 2 has it's own button input 3 has it's own button etc. the only way what i'm looking for is possible is if you can detect the active input box when enter is pressed, other wise it won't work.
xcal Posted October 7, 2006 Posted October 7, 2006 Did you try what sirhc posted? It does exactly what you want. How To Ask Questions The Smart Way
xcal Posted October 7, 2006 Posted October 7, 2006 Here, try this... expandcollapse popup#include <GUIConstants.au3> Opt('GUIOnEventMode', 1) ;define $hotkey = "{ENTER}" ;gui_starts here $hotkey_is_set = 0 $main_gui = GUICreate("Press Enter...", 220, 250) ; will create a dialog box that when displayed is centered $input1 = GUICtrlCreateInput("Field 1", 10, 10, 200, 20) $input2 = GUICtrlCreateInput("Field 2", 10, 40, 200, 20) $input3 = GUICtrlCreateInput("Field 3", 10, 70, 200, 20) $input4 = GUICtrlCreateInput("Field 4", 10, 100, 200, 20) $btn_1 = GUICtrlCreateButton("Button 1", 10, 130, 200, 20) $btn_2 = GUICtrlCreateButton("Button 2", 10, 160, 200, 20) $btn_3 = GUICtrlCreateButton("Button 3", 10, 190, 200, 20) $btn_4 = GUICtrlCreateButton("Button 4", 10, 220, 200, 20) GUISetOnEvent($GUI_EVENT_CLOSE, 'quit') GUICtrlSetOnEvent($btn_1, 'btn1') GUICtrlSetOnEvent($btn_2, 'btn2') GUICtrlSetOnEvent($btn_3, 'btn3') GUICtrlSetOnEvent($btn_4, 'btn4') ;show the gui GUISetState(@SW_SHOW) ;start the script While 1 set_executekey() Sleep(100) WEnd ;de/activate hotkey Func set_executekey($mbox = 0) ;deactivate hotkey when window is active and msgbox is open ;(to prevent msgbox from open again when pressing enter while box is visible) If $mbox = 1 Then HotKeySet($hotkey) $hotkey_is_set = 0 ;activate hotkey when window is active and hotkey isn`t set yet (checks $hotkey_is_set var) ElseIf WinActive($main_gui) Then If $hotkey_is_set = 0 Then HotKeySet($hotkey, "check_and_go") $hotkey_is_set = 1 EndIf ;deactivates hotkey if window isn`t active anymore and the hotkey was set before Else If $hotkey_is_set = 1 Then HotKeySet($hotkey) EndIf EndIf EndFunc ;==>set_executekey Func check_and_go() ;you can shorten this function if you use an array If ControlGetFocus($main_gui) = "Edit1" Then set_executekey(1) btn1() ElseIf ControlGetFocus($main_gui) = "Edit2" Then set_executekey(1) btn2() ElseIf ControlGetFocus($main_gui) = "Edit3" Then set_executekey(1) btn3() ElseIf ControlGetFocus($main_gui) = "Edit4" Then set_executekey(1) btn4() EndIf EndFunc Func btn1() MsgBox(0, '', 'Button 1') EndFunc Func btn2() MsgBox(0, '', 'Button 2') EndFunc Func btn3() MsgBox(0, '', 'Button 3') EndFunc Func btn4() MsgBox(0, '', 'Button 4') EndFunc Func quit() Exit EndFunc It's what sirhc (chris!) posted, just in eventmode, and with buttons. How To Ask Questions The Smart Way
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