Autoseek Posted May 17, 2014 Share Posted May 17, 2014 Hello, I apologize for asking a (probably) most trivial question, but I am simply not getting anywhere. This is the basic setup: Local $hGUI = GUICreate("Tracker", 380, 300) Local $iAddInput = GUICtrlCreateInput("", 15, 15, 200, 18) Local $iAddButton = GUICtrlCreateButton("New", 230, 15, 60, 20) I have an input field, and if the "New" button is clicked, the input is used for further processing: While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $iAddButton ; do something EndSwitch WEnd That is all working fine. Now, I would like that the "Case $iAddButton" part is executed also, when the user enters "ENTER" (or "RETURN") when typing in the input field. I am afraid I don't understand the basic idea on how to implement this. I have reviewed many examples involving _IsPressed() and GUIRegisterMsg($WM_COMMAND, ...), but I am not getting at what I need to do in my specific example. Would anyone have a code snippet or a pointer to a webpage available, that explains this? That would be greatly appreciated! Thank you! Best regards Reiner Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted May 17, 2014 Moderators Solution Share Posted May 17, 2014 Autoseek,First, welcome to the AutoIt forums. The easiest way to do this is to use an accelerator key and check if the focus is on the required input:#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> $hGUI = GUICreate("Tracker", 380, 300) $cAddInput = GUICtrlCreateInput("", 15, 15, 200, 18) $hAddInput = GUICtrlGetHandle($cAddInput) $cExtraInput = GUICtrlCreateInput("", 15, 45, 200, 18) $cAddButton = GUICtrlCreateButton("New", 230, 15, 60, 20) $cEnterPressed = GUICtrlCreateDummy() GUISetState() Global $aAccelKeys[][2] = [["{ENTER}", $cEnterPressed]] GUISetAccelerators($aAccelKeys) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $cEnterPressed If _WinAPI_GetFocus() = $hAddInput Then ; Run the button case ContinueCase EndIf Case $cAddButton MsgBox($MB_SYSTEMMODAL, "Hi", "Something should happen") EndSwitch WEndYou can check that if the focus is on the other input then the {ENTER} key does not action. All clear5? M23 Autoseek 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 17, 2014 Moderators Share Posted May 17, 2014 (edited) See here for a snippet I provided just the other day for using Enter on an input field. Edit: Dang, too slow Edited May 17, 2014 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Autoseek Posted May 17, 2014 Author Share Posted May 17, 2014 Thank you both so much. That is really a big help! And, thank you especially for how to solve this in the Switch/Case context using the ContinueCase. Oh boy, I am really happy. Looks like I can finish this today! Thanks! Best regards Reiner Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 17, 2014 Moderators Share Posted May 17, 2014 Autoseek,Glad we could help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted May 17, 2014 Share Posted May 17, 2014 >Without accelerators AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Autoseek Posted May 17, 2014 Author Share Posted May 17, 2014 (edited) And, to confirm, it is working perfectly with my application Personally, I like that "ContinueCase" a lot. Also, thank you for the suggestion with $BS_DEFPUSHBUTTON. This may also be very useful one day. (For this particular application, I need to confirm the focus.) Again, you made my day! Cheers Reiner Edited May 17, 2014 by Autoseek 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