crzymnmchl Posted June 11, 2013 Share Posted June 11, 2013 Is it possible to get the handle of a control that is the object of a mouseClick? tia. Link to comment Share on other sites More sharing options...
FireFox Posted June 11, 2013 Share Posted June 11, 2013 (edited) Hi,Welcome to the autoit forum Yes, take a look at the _WinAPI_WindowFromPoint function.Edit: And the function _IsPressed to detect the mouseclick. There is maybe more reliable functions for your needs, can you tell us what are you trying to do?Br, FireFox. Edited June 11, 2013 by FireFox Link to comment Share on other sites More sharing options...
Solution Malkey Posted June 11, 2013 Solution Share Posted June 11, 2013 This might give you some ideas. Press"Esc" key to exit. #include <Misc.au3> #include <WinAPI.au3> Local $hDLL = DllOpen("user32.dll") While 1 If _IsPressed("01", $hDLL) Then ; Left mouse button ; Wait until key is released. While _IsPressed("01", $hDLL) Sleep(50) WEnd $hCtrlHnd = ControlGetHandle("", "", "") ConsoleWrite("Ctrl Id #" & _WinAPI_GetDlgCtrlID($hCtrlHnd) & @TAB & "Ctrl Handle:" & $hCtrlHnd & @CRLF) ElseIf _IsPressed("1B", $hDLL) Then ; Press Esc key to exit. MsgBox(0, "_IsPressed", "The Esc Key was pressed, therefore we will close the application.", 3) ExitLoop EndIf Sleep(50) WEnd DllClose($hDLL) Link to comment Share on other sites More sharing options...
jdelaney Posted June 12, 2013 Share Posted June 12, 2013 (edited) Here is another one...it will grab ALL controls that the mouse cords are in, at release of click (so grabs groups behind the actual control, etc)...esc to stop...oh, might want to verify that the control is visible...or if win is tabbed, it will grab from ALL tabs as well one more note: to grab a button, without performing the action of the button, click on window anywhere, and release on the button expandcollapse popupHotKeySet("{ESC}", "_Exit") Func _Exit() Exit EndFunc ;==>_Exit #include <Misc.au3> #include <Array.au3> AutoItSetOption("MouseCoordMode", 2) While 1 If _IsPressed(01) Then While _IsPressed(01) WEnd $aMouse = MouseGetPos() ConsoleWrite("Mouse [x/y]=[" & $aMouse[0] & "/" & $aMouse[1] & "]" & @CRLF) ConsoleWrite("Active WinHandle=[" & WinGetHandle("[ACTIVE]") & "] title=[" & WinGetTitle("[ACTIVE]") & "] ") $windowList = WinGetClassList("[ACTIVE]") $aClassList = StringSplit($windowList, @CRLF) _ArrayDelete($aClassList, UBound($aClassList)) _ArrayDelete($aClassList, 0) _ArraySort($aClassList) $iCurrentClass = "" $iCurrentCount = 1 $iTotalCounter = 1 For $i = 0 To UBound($aClassList) - 1 If $aClassList[$i] = $iCurrentClass Then $iCurrentCount += 1 Else $iCurrentClass = $aClassList[$i] $iCurrentCount = 1 EndIf $hControl = ControlGetHandle("[ACTIVE]", "", $iCurrentClass & $iCurrentCount) $aPos = ControlGetPos("[ACTIVE]", "", $hControl) If $aPos[0] < $aMouse[0] And ($aPos[0] + $aPos[2]) > $aMouse[0] And $aPos[1] < $aMouse[1] And ($aPos[1] + $aPos[3]) > $aMouse[1] Then ConsoleWrite(@CRLF & "Control found=[" & $hControl & "]" ) EndIf Next ConsoleWrite(@CRLF & "done in loop" & @CRLF) Sleep(500) EndIf WEnd Edited June 12, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
crzymnmchl Posted June 12, 2013 Author Share Posted June 12, 2013 (edited) I am making a random xy MouseClick on a Win app - not totally random - I know there is a control under the click. Since there a lot of WinControls I did not map them all to their coordinates and names ... I could not work out how to make the jump from random MouseClick to the actual WinControl that got clicked. Thank you very much for all the info - going to read and inwardly digest :-) - all info looks good - I just clicked one of them to mark answered. Edited June 12, 2013 by crzymnmchl 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