AndyS01 Posted January 26, 2010 Share Posted January 26, 2010 I have an AutoIT GUI that has 2 text controls and a button. When I click on the button, I want to display the text from the last of the 2 text input controls that had focus. I couldn't find a way to capture on-focus events, so I handled all mouse left button events and looked to see if they were from one of the 2 text input controls, and if so, remember the control ID. However, when I get the interrupt, the @GUI_CtrlId value is always -7 Here is an extract from my script: #include <GuiConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Opt('MustDeclareVars', 1) Opt("GUIEventOptions", 1) Global $iID = 0, $hMainwin, $Btn, $Input1, $Input2 $hMainwin = GUICreate("main", 120, 100) $Input1 = GUICtrlCreateInput("text 1", 10, 10, 100, 20) $Input2 = GUICtrlCreateInput("text 2", 10, 30, 100, 20) $Btn = GUICtrlCreateButton("Button", 10, 50, 100, 20) ConsoleWrite("+++: $Input1 = " & $Input1 & @CRLF) ConsoleWrite("+++: $Input2 = " & $Input2 & @CRLF) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Event_Focus"); Focus started on a control GUICtrlSetOnEvent($Btn, 'handle_btn') GUISetState() While 1 Sleep(500) ; sleep a short while WEnd Func Event_Focus() Local $id = @GUI_CtrlId ConsoleWrite("+++: Event_Focus() called. ID = " & $id & @CRLF) If (($id == $Input1) Or ($id == $Input2)) Then $iID = $id EndFunc ;==>Event_Focus Func handle_btn() MsgBox(0, "INFO", "$iID = " & $iID & @CRLF & "text ==>" & GUICtrlRead($iID) & "<==") Exit (1) EndFunc ;==>handle_btn Andy Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 26, 2010 Moderators Share Posted January 26, 2010 (edited) AndySO1,Here is one way to do it. You could faff around with EN_SETTFOCUS and EN_KILLFOCUS messages, but just looking for the last active input seems easier: expandcollapse popup#include <GuiConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Opt("GUIOnEventMode", 1) Opt('MustDeclareVars', 1) Opt("GUIEventOptions", 1) Global $iLast_Focus, $hInput_1, $hInput_2, $iActive Global $iID = 0, $hMainwin, $Btn, $Input1, $Input2 $hMainwin = GUICreate("main", 120, 100) $Input1 = GUICtrlCreateInput("text 1", 10, 10, 100, 20) $hInput_1 = GUICtrlGetHandle(-1) $Input2 = GUICtrlCreateInput("text 2", 10, 30, 100, 20) $hInput_2 = GUICtrlGetHandle(-1) $Btn = GUICtrlCreateButton("Button", 10, 50, 100, 20) ConsoleWrite("+++: $Input1 = " & $Input1 & @CRLF) ConsoleWrite("+++: $Input2 = " & $Input2 & @CRLF) GUICtrlSetOnEvent($Btn, 'handle_btn') GUISetState() While 1 Sleep(10) ; sleep a short while $iLast_Focus = _WinAPI_GetFocus() Switch $iLast_Focus Case $hInput_1 $iActive = $Input1 Case $hInput_2 $iActive = $Input2 EndSwitch WEnd Func handle_btn() MsgBox(0, "INFO", "$iID = " & $iActive & @CRLF & "text ==>" & GUICtrlRead($iActive) & "<==") Exit (1) EndFunc ;==>handle_btnI hope this does what you want. M23Edit: SO1 = ? Edited January 26, 2010 by Melba23 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...
AdmiralAlkex Posted January 26, 2010 Share Posted January 26, 2010 Edit: SO1 = ? I believe it says "AndyS[zero]1" (notice the different in width etc between 0 and O). .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...
Moderators Melba23 Posted January 26, 2010 Moderators Share Posted January 26, 2010 AdmiralAlkex,You are almost certainly correct - my old eyes you know..... It is just that S(Oh)1 used to mean something in a past life. 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...
AdmiralAlkex Posted January 26, 2010 Share Posted January 26, 2010 It is just that S(Oh)1 used to mean something in a past life. Past life? Sounds coolNow where did Andy go? *knock knock* .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...
PsaltyDS Posted January 26, 2010 Share Posted January 26, 2010 I trapped WM_COMMAND and it seemed to only send EN_CHANGE. Was expecting EN_SETFOCUS and EN_KILLFOCUS, but never saw them. Settled on this since all he wanted was the last Input to send ANY message: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $iID = 0, $hMainwin, $idBtn, $idInput1, $hInput1, $idInput2, $hInput2 $hMainwin = GUICreate("main", 120, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") $idInput1 = GUICtrlCreateInput("text 1", 10, 10, 100, 20) $hInput1 = ControlGetHandle($hMainwin, "", $idInput1) $idInput2 = GUICtrlCreateInput("text 2", 10, 30, 100, 20) $hInput2 = ControlGetHandle($hMainwin, "", $idInput2) $idBtn = GUICtrlCreateButton("Button", 10, 50, 100, 20) GUICtrlSetOnEvent(-1, 'handle_btn') GUISetState() GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Sleep(10) ; sleep a short while WEnd Func _WM_COMMAND($hWnd, $iMsg, $WPARAM, $LPARAM) Local $WPARAM_Lo = BitAND($WPARAM, 0x0000FFFF) Switch $LPARAM Case $hInput1, $hInput2 $iID = $WPARAM_Lo EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND Func handle_btn() ConsoleWrite("Button Hit: $iID = " & $iID & "; text = " & GUICtrlRead($iID) & @LF) EndFunc ;==>handle_btn Func _Quit() Exit EndFunc ;==>_Quit Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AndyS01 Posted January 27, 2010 Author Share Posted January 27, 2010 Thank you very much, folks, the suggested solutions 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