queensoft Posted July 18, 2024 Posted July 18, 2024 I have a custom made Python script (both .py source code and .exe compiled versions. I need to fill in the text fields and click some buttons. Detection works perfectly, actual ControlClick / ControlSend does not. * Au3Info_x64.exe = OK - see attached image. One quick note here: when I drag & hover the target cursor, to get the info, the control is not selected / highlighted (like most other windows). It's just a quick flash, but the info is presented perfectly. * WinActivate / WinExists = OK #RequireAdmin is present, as is Opt('WinTitleMatchMode', 2) * This script works perfectly, I get the exact same info as Au3Info_x64.exe, all controls Handles, ClassNN, positions, everything expandcollapse popupFunc GetAllWindowsControls($hCallersWindow, $bOnlyVisible=Default, $sStringIncludes=Default, $sClass=Default) If Not IsHWnd($hCallersWindow) Then ConsoleWrite("$hCallersWindow must be a handle...provided=[" & $hCallersWindow & "]" & @CRLF) Return False EndIf ; Get all list of controls If $bOnlyVisible = Default Then $bOnlyVisible = False If $sStringIncludes = Default Then $sStringIncludes = "" If $sClass = Default Then $sClass = "" $sClassList = WinGetClassList($hCallersWindow) ; Create array $aClassList = StringSplit($sClassList, @CRLF, 2) ; Sort array _ArraySort($aClassList) _ArrayDelete($aClassList, 0) ; Loop $iCurrentClass = "" $iCurrentCount = 1 $iTotalCounter = 1 If StringLen($sClass)>0 Then For $i = UBound($aClassList)-1 To 0 Step - 1 If $aClassList[$i]<>$sClass Then _ArrayDelete($aClassList,$i) EndIf Next EndIf For $i = 0 To UBound($aClassList) - 1 If $aClassList[$i] = $iCurrentClass Then $iCurrentCount += 1 Else $iCurrentClass = $aClassList[$i] $iCurrentCount = 1 EndIf $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]") $text = StringRegExpReplace(ControlGetText($hCallersWindow, "", $hControl), "[\n\r]", "{@CRLF}") $aPos = ControlGetPos($hCallersWindow, "", $hControl) $sControlID = _WinAPI_GetDlgCtrlID($hControl) $bIsVisible = ControlCommand($hCallersWindow, "", $hControl, "IsVisible") If $bOnlyVisible And Not $bIsVisible Then $iTotalCounter += 1 ContinueLoop EndIf If StringLen($sStringIncludes) > 0 Then If Not StringInStr($text, $sStringIncludes) Then $iTotalCounter += 1 ContinueLoop EndIf EndIf If IsArray($aPos) Then ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] IsVisible=[" & $bIsVisible & "] Text=[" & $text & "]." & @CRLF) Else ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF) EndIf If Not WinExists($hCallersWindow) Then ExitLoop $iTotalCounter += 1 Next EndFunc ;==>GetAllWindowsControls * As far as I remember, IUIAutomation - detection part - also works OK, but not the click part. I'll try to work on this a bit more. And yet, after all this detection working OK, ControlClick / ControlSend does not. ControlClick just quickly flashes the buttons, but no action is performed (like open Browse dialog or show cursor inside text field)
Andreik Posted July 18, 2024 Posted July 18, 2024 Not ideal but for testing purpose, did you tried a combination of ControlFocus() + Send()?
queensoft Posted July 19, 2024 Author Posted July 19, 2024 Tried just now - not working. Of course, there are other options, like MouseClick into several positions, but they are not very elegant.
queensoft Posted July 19, 2024 Author Posted July 19, 2024 I can get the control properties just fine: handle, position, Instance, Class, ClassNN - verified by 3 different sources. There are no Name, ID properties. What I cannot do is I cannot control (click, focus, send text) any of the controls. I will try your suggestion in 10-15 minutes, I seed it's based on UIAWrappers.au3
ioa747 Posted July 19, 2024 Posted July 19, 2024 another classic case is if the program is run with administrator rights, then the script must also have administrator rights I know that I know nothing
queensoft Posted July 19, 2024 Author Posted July 19, 2024 22 hours ago, queensoft said: #RequireAdmin is present, as is Opt('WinTitleMatchMode', 2) I'm on admin account, UAC disabled, everything runs as admin (no worries, I've been doing this for a while, like .... years, did Windows 3.1 even had admin rights ?! , and nothing bad happened)
queensoft Posted July 19, 2024 Author Posted July 19, 2024 1 hour ago, ioa747 said: try Tried it. It's only for detection, which is already OK. This also works OK, same Handle, Class, Instance.... But as far as click..... still no luck. I tried like this: #include "UIAutomation.au3" WinActivate("actual window title") Sleep(333) _UIA_ControlClick(0x000801DE, 0x000C0C48, "left", 1) ; window handle, control handle, button, number of clicks _UIA_ControlClick(0x000801DE, 0x000C0C48, "invoke", 1) _UIA_ControlSend(0x000801DE, 0x000C0C48, "xxxx")
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