SpookMeister Posted November 23, 2005 Share Posted November 23, 2005 I'm looking for a way to make it so after a user types something in an input and hits the ENTER key it submits, triggers, pushes a button, or whatever else might have to happen to make it do what I need. For example, in the following code: #include <GUIConstants.au3> GUICreate("MyProg", 400, 100) $input_1 = GUICtrlCreateInput("", 30, 40, 300, 25) $btn_1 = GUICtrlCreateButton("OK", 340, 40) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $btn_1 MsgBox(0, "Info", GUICtrlRead($input_1)) EndSelect WEnd After the user types whatever, and hits the ENTER key expecting it to submit the info. I'd like them not to have to hit "OK" I'm sure I've seen something about this before, but I can't seam to find it now. [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
Josbe Posted November 23, 2005 Share Posted November 23, 2005 You can try: HotKeySet("{ENTER}", "_btnSubmit") #include <GUIConstants.au3> GUICreate("MyProg", 400, 100) $input_1 = GUICtrlCreateInput("", 30, 40, 300, 25) $btn_1 = GUICtrlCreateButton("OK", 340, 40) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $btn_1 HotKeySet("{ENTER}") MsgBox(0, "Info", GUICtrlRead($input_1)) HotKeySet("{ENTER}", "_btnSubmit") EndSelect WEnd Func _btnSubmit() $msg = $btn_1 EndFunc Of course, maybe isn't the best way. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
SpookMeister Posted November 23, 2005 Author Share Posted November 23, 2005 Interesting... #include <GUIConstants.au3> HotKeySet("{ENTER}","Submit") GUICreate("MyProg", 400, 100) $input_1 = GUICtrlCreateInput("", 30, 40, 300, 25) $btn_1 = GUICtrlCreateButton("OK", 340, 40) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $btn_1 Submit() EndSelect WEnd Func Submit() If WinActive("MyProg") Then MsgBox(0, "Info", GUICtrlRead($input_1)) ; Whatever else I want to do EndIf EndFunc I wasn't sure why you have all of the HotKeySet's within the case statement, but it seams to work well the way I have it here. Thanks [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
Josbe Posted November 23, 2005 Share Posted November 23, 2005 (edited) .....I wasn't sure why you have all of the HotKeySet's within the case statement, but it seams to work well the way I have it here.ThanksUnregister the "ENTER" key while the Msgbox is displayed and that enable the ENTER key for close the Msgbox through the keyboard.Anyways, you have a good way. Edited November 23, 2005 by Josbe AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
SlimShady Posted November 23, 2005 Share Posted November 23, 2005 #include <GUIConstants.au3> GUICreate("MyProg", 400, 100) $input_1 = GUICtrlCreateInput("", 30, 40, 300, 25) $btn_1 = GUICtrlCreateButton("OK", 340, 40, -1, -1, $BS_DEFPUSHBUTTON) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $btn_1 MsgBox(0, "Info", GUICtrlRead($input_1)) EndSelect WEnd You're welcome Link to comment Share on other sites More sharing options...
SpookMeister Posted November 23, 2005 Author Share Posted November 23, 2005 Ah Ha!! Thats the one I was thinking of originaly. Much Thanks SS. [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
Greenseed Posted November 26, 2005 Share Posted November 26, 2005 hello i have this for you! it a call to the kernel! i use it for a chat software! he does not capture the key like Hotkey() it check for the last key pressed at the kernel level! very simple ;the function who call the kernel it return 1 for TRUE and 0 for False Func _IsPressed($hexKey) Local $aR, $bRv $hexKey = '0x' & $hexKey $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey) If $aR[0] <> 0 Then $bRv = 1 Else $bRv = 0 EndIf Return $bRv EndFunc If _IsPressed('0d') and winactive("MyWindows") Then do what you wanna ; the 0d = the ENTER ;it tell if the last key press is ENTER and the windows active was my soft then gogogo GreenseedMCSE+I, CCNA, A+Canada, QuebecMake Love Around You. 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