mike2003 Posted January 25, 2020 Share Posted January 25, 2020 (edited) How to register a function when I enter text and press the Enter button? I tried this Case $MyCombo in main GUI Loop. But it works even when I just select a new value from the list. And this is not necessary. Only on Enter in Combo field Edited January 25, 2020 by mike2003 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 25, 2020 Moderators Share Posted January 25, 2020 mike2003, I would see if the combo edit box has focus when Enter is pressed - like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPISysWin.au3> #include <GuiComboBox.au3> #include <Misc.au3> Global $tInfo $hDLL = DllOpen("user32.dll") $hGUI = GUICreate("Test", 500, 500) $cCombo = GUICtrlCreateCombo("", 10, 10, 200, 20) GUICtrlSetData($cCombo, "1|2|3") GUISetState() ; Get handle of combo edit box If _GUICtrlComboBox_GetComboBoxInfo($cCombo, $tInfo) Then $hComboEdit = DllStructGetData($tInfo, "hEdit") Else ConsoleWrite("Fail" & @CRLF) Exit EndIf While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($hDLL) Exit EndSwitch ; Check for Enter press If _IsPressed("0D", $hDLL) Then ; Check if combo edit box has focus If _WinAPI_GetFocus() = $hComboEdit Then ConsoleWrite(GUICtrlRead($cCombo) & @CRLF) EndIf EndIf ; Wait for Enter release - try without this to see why you need it! While _IsPressed("0D", $hDLL) Sleep(250) WEnd WEnd M23 mike2003 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...
Nine Posted January 25, 2020 Share Posted January 25, 2020 Or a little different approach : #include <GUIConstants.au3> #include <GuiComboBox.au3> Local $hGUI = GUICreate("Test") Local $cCombo = GUICtrlCreateCombo("", 10, 10, 200, 20) GUICtrlSetData($cCombo, "1|2|3") GUICtrlCreateLabel ("Edit :", 10, 50,50,20) Local $cEdit = GUICtrlCreateInput ("", 50, 50, 150, 20) Local $cButton = GUICtrlCreateButton("OK", 10, 100, 100, 25) Local $cDummy = GUICtrlCreateDummy() Local $aAccelKeys[1][2] = [["{ENTER}", $cDummy]] GUISetAccelerators($aAccelKeys) GUISetState() Local $tInfo _GUICtrlComboBox_GetComboBoxInfo($cCombo, $tInfo) Local $hCombo = DllStructGetData($tInfo, "hEdit") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $cButton ExitLoop Case $cDummy If ControlGetHandle($hGUI, "", ControlGetFocus ($hGUI)) = $hCombo Then ; put your code here ConsoleWrite(GUICtrlRead($cCombo) & @CRLF) EndIf EndSwitch WEnd mike2003 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mike2003 Posted January 26, 2020 Author Share Posted January 26, 2020 (edited) 19 hours ago, Nine said: different approach Good! 21 hours ago, Melba23 said: I would see if the combo edit box has focus when Enter is pressed I have error - no file WinAPISysWin.au3 updt: works without it Edited January 26, 2020 by mike2003 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 27, 2020 Moderators Share Posted January 27, 2020 mike2003, It sounds as if you are running an older AutoIt release - there was a major reorganising of the WinAPI UDFs by jpm for the last one. So you can probably manage with including just WinAPI.au3. 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...
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