WoodGrain Posted April 22, 2016 Posted April 22, 2016 Hi All, I'm wanting to learn how to use ControlSend or ControlClick to be able to click a button when prompted, part of the problem is the button text changes. The button I want to click displays "NO (XX)" where XX is a countdown each second from 90 - image attached. I've not done Control based code before, so the below code may be wrong lol, but this is what I've got so far: While 1 If WinExists("System", "reboot") Then Local $hWnd = WinWait("System", "reboot", 5) Local $iPID = WinGetProcess($hWnd) ControlClick($hWnd, "", "[CLASS:Button; Text: NO"] ;ProcessClose($iPID) EndIf Sleep(10000) WEnd Thanks!
alien4u Posted April 22, 2016 Posted April 22, 2016 What I do when I can't directly send to the specific control is use TAB and ENTER, like this: WinWait ("[CLASS:#32770]") $id = WinGetHandle("[CLASS:#32770]") ControlSend($id, "", "","{TAB 3}") ControlSend($id, "", "","{ENTER}") Maybe this work for you, but I'm almost sure there is a better way to do it and the ones with more experience will say. Regards Alien.
InunoTaishou Posted April 22, 2016 Posted April 22, 2016 ControlClick($hWnd, "", "[Class:Button;Instance:2]") Idk what instance the No button really is but since there's only two buttons on there, I'm gonna guess it's 2. If you put the finder tool over it (Autoit Window info tool) you can see what instance it is.
WoodGrain Posted April 22, 2016 Author Posted April 22, 2016 Thanks Inuno, that looks like what I need. I don't have access to the dialogue as it tends to run when I'm away from my computer, but I could write a log file of when it happens that way I'll know if it's working or not.
InunoTaishou Posted April 22, 2016 Posted April 22, 2016 You could use this to log what instance the button is for the dialog, in case it's not actually 2. Go through every button control on the dialog and if it matches the expression, click it. #include <Array.au3> Global $hWnd = WinGetHandle("System", "reboot") Global $aClassList = StringSplit(WinGetClassList($hWnd), @LF, 2) For $i = UBound($aClassList) - 1 To 0 Step -1 If ($aClassList[$i] <> "Button") Then _ArrayDelete($aClassList, $i) Next For $i = 1 to UBound($aClassList) Local $sButtonText = ControlGetText($hWnd, "", "[Class:Button;Instance:" & $i & "]") If (StringRegExp($sButtonText, "(?i)No \(\d{1,2}\)")) Then ControlClick($hWnd, "", "[Class:Button;Instance:" & $i & "]") ExitLoop EndIf Next
WoodGrain Posted April 26, 2016 Author Posted April 26, 2016 ooh, that's cool, I will definitely use that! Thanks! I'll spend some time looking through the RegExp code too, looks like exactly what is needed for dealing with a button with a changing value, cheers.
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