Sign in to follow this  
Followers 0
Michiel

Get color of text from checkbox control

29 posts in this topic

Hi all. I'm trying to automate a program which has a list of checkboxes with labels, and I need to select some checkboxes from the set and determine the color of the accompanying text.

Is this possible? I see when creating a GUI in Autoit, all sorts of styles for controls can be defined, but when one is reading out a control from a program to be automated, I don't see much else but:

https://www.autoitscript.com/autoit3/docs/functions/PixelGetColor.htm

Which is where I would need to be sure I don't get the coordinate of the upper left corner of the control, rather than the actual accompanying text to the checkbox. It is that text which I need to know the foreground color of..

Any tips?

Share this post


Link to post
Share on other sites



This would be way easier if you could provide a sample of what the checkboxes looked like. Pixelgetcolor will get the position of of a pixel on the screen. If the screen moves then pixelgetcolor probably wont work for you. Can you provide a screen shot? If you know the current position of the checkbox when you select it and you know the distance from where the checkbox to the text is and the background is always the same color (or you know a range of colors that the background will always be and it doesn't overlap on the color of what the text color is) then this can be done with a for loop:

Local $X1 = 123;Whatever the x position is of the checkbox
Local $Y1 = 234;position of the y pixel of the checkbox
Local $Distance = 50;number of pixels to the right of the checkbox to start scanning for text color
Local $CPos = $X1 + $Distance;CPos is the first pixel (X Position) position to start scanning for a color in the test
For $i = 1 To 30;check 30 pixel positions for the text color
     $C1 = PixelGetcolor($CPos,$Y1)
     If $C1 <> 16777215 Then;If the pixel color is a color other than white (16777215) Then...
     MsgBox(0,"Color of the text","Color of text is " & $C1);message box of color
     ExitLoop;you found your color, stop looking
     EndIf
     $CPos += 3;expand the search x position by 3 pixels(check 3 pixels to the right for the last X position location)
Next

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

I wanted to paste an image but I got "You are not allowed to use that image extension on this community".. And I can't find where to upload files, so here is a link to imgur:

'>

It's on the left-hand side, under the tab "Common Apps". I hope this helps! So does this mean it isn't possible to get a handle to a control and then browse the control's properties, such as the foreground text color? Thanks a mil for the example code! I have only 5 more posts today, this one included, so I hope I can provide everything you want to see before I run out. :)

 

Share this post


Link to post
Share on other sites

In this example I would instead use pixelsearch to search for a larger block of pixels. I put together the following with the help of others here a long time ago to get the x y position and color values of where my mouse was on the fly:

#include <GuiConstants.au3>
;#include <ControlGetHandleByPos.au3>

Opt("GUIOnEventMode", 1)
Opt("WinTitleMatchMode", 4)
Global $xoffset = 10;X axis distance from mouse pointer to blue label
Global $yoffset = 23;Y axis distance from mouse pointer to blue label
Global $wposx, $wposy, $dt, $cwin, $xcalcl, $xcalcr, $ycalc, $cpos, $pos, $tpos, $hexv, $pcolor
Global $title = "Your Title Here"
HotKeySet("{ESC}", "Terminate")
$pgui = GUICreate($title, 250, 13, -1, -1, $ws_popup);Rear place holder for back of the blue label box (Title, Length of the blue lable box, Height of the blue label box,,)
$startlab = GUICtrlCreateLabel(" X: 0000, Y: 0000", 0, 0, 250, 13)
GUICtrlSetBkColor($startlab, 13434879);blue label box color
WinSetOnTop($pgui, "", 1)
GUISetState(@SW_SHOW)
While 1
    _nmgp()
WEnd

Func _nmgp()
    Local $_cpos = MouseGetPos();get current position of the mouse on desktop
    Sleep(10)
    $pcolor = PixelGetColor($_cpos[0], $_cpos[1]);help
    $pos = MouseGetPos()
    GUICtrlSetData($startlab, " X: " & $pos[0] & ", Y: " & $pos[1] & " HEX: " & Hex($pcolor, 6) & " DEC: " & $pcolor)

;************************************ Moves the blue label with the mouse *****************************
    If $dt = 1 Then
        $xcalcr = 0.95 * @DesktopWidth
        $xcalcl = 0.05 * @DesktopWidth
        $ycalc = 0.9 * @DesktopHeight
        If $pos[1] > $ycalc Then
            $wposy = $pos[1] - $yoffset * 2
        Else
            $wposy = $pos[1] + $yoffset
        EndIf
        If $pos[0] > $xcalcr Then
            $wposx = $pos[0] - $xoffset * 3
        ElseIf $pos[0] < $xcalcl Then
            $wposx = $pos[0] + 10
        Else
            $wposx = $pos[0] - $xoffset
        EndIf
    Else
        _clientmouse()
    EndIf
    WinMove($title, "", $wposx, $wposy)
;************************************ End Moves the blue label with the mouse ***************************

EndFunc

Func _clientmouse()
    Opt("MouseCoordMode", 1)
    $tpos = MouseGetPos()
    $cpos = WinGetPos($cwin)
    $xcalcr = 0.95 * $cpos[2]
    $xcalcl = 0.95 * $cpos[2]
    $ycalc = 5.0 * $cpos[3];Y axis for offsetting the text box when you reach the top of the screen (so you can stil see the coordinates)
    If $tpos[1] > $ycalc Then
        $wposy = $tpos[1] - $yoffset * 2; Y Axis to determine the distance from the mouse pointer and the blue text box
    Else
        $wposy = $tpos[1] + $yoffset
    EndIf
    If $tpos[0] > $xcalcr Then
        $wposx = $tpos[0] - $xoffset - $xcalcr ; X Axis to determine the distance from the mouse pointer and the blue text box
    ElseIf $tpos[0] < $xcalcl Then
        $wposx = $tpos[0] + 10
    Else
        $wposx = $tpos[0] - $xoffset
    EndIf
EndFunc

Func terminate()
    Exit 0
EndFunc

If you compile and run this it will add a tooltip next to your mouse that gives you the x y pos and the hex and dec value for where your mouse is now(the pointed tip of the mouse).

Since the list of items on the left of your program do not scroll, you could use pixelchecksum to check all of the boxes and if one was checked then you could determine the checkbox location and select it and then check for a color on the right. If you know the control of the checkbox then you might be able to control it from that value.

Why don't you just select perform updates on all the software?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

Thanks for the code example, I will use that. Right now the request is to at least check the checkboxes for a list of 6 applications, so if the color detection fails I will just check those boxes and run it. Currently I'm testing with the following code:

; MsgBox(0, 'Debug', @ScriptDir)
Local $aChkBoxes[] = ['Chk_AdobeReader', 'Chk_FlashPlugin', 'Chk_FlashPlayer', 'Chk_AdobeAir', 'Chk_AdobeShockwave', 'Chk_MSSilverlight']
Run('PatchMyPC.exe')
If @error Then
   MsgBox(0, 'Error', 'Error="' & @error & '"')
   Exit
Endif
Local $hWnd = WinWaitActive('[REGEXPTITLE:Patch My PC.*]')
;Local $handle = ControlGetHandle("[REGEXPTITLE:Patch My PC.*]", "")
;MsgBox(0, 'Debug', $winHandle)
;Exit
WinActivate($hWnd)
Local $hChkBox
For $i = 0 To UBound($aChkBoxes) - 1
   MsgBox(0, 'Debug', $aChkBoxes[$i])
   $hChkBox = ControlGetHandle($hWnd, '', '[NAME:' & $aChkBoxes[$i] & ']')
   ;MsgBox(0, 'Debug', 'Handle checkbox = ' & $hChkbox)
   ;Local $rv = ControlCommand($hWnd, '', $hChkBox, "IsChecked", "")
   ;Local $rv = ControlCommand($hWnd, '', '[NAME:' & $aChkBoxes[$i] & ']', "IsChecked", "")
   If @error <> 0 Then
      MsgBox(0, 'Debug', 'Error: ' & @error)
   EndIf
   ;Msgbox(0, 'Debug', 'Checked? ' & $rv)
   ControlCommand($hWnd, "", $hChkbox, "Check", "")
Next
Sleep(2000)
Exit

I have a different problem now: checking the checkboxes succeeds perfectly: but it's a "toggle", so if it was already checked, like with Silverlight, it will be unchecked. So I get 5 checked and Silverlight unchecked. I tried to read the checkbox state with "IsChecked", but I always get 0 back... What's going on? Am I querying a label rather than a checkbox? Using AutoIt Window Info, it always outlines the checkbox and the text next to it; I can't select the checkbox all by itself. I don't know why I always get 0 back; When I checked for errors in the code above (never mind the commenting, the error check was positioned right after "IsChecked" .. I get no errors...

Share this post


Link to post
Share on other sites

If it's a bug in the code then you can either wait for a fix or find another way to do what you want to do. From what I'm seeing you are well versed in the concepts of computer logic and how to implement it in autoit. Why don't you just make your own program in autoit that does all of this rather than backpack on someone else's program? Also do you have a link for this program?

For the toggle issue you can use pixelchecksum instead of selecting the box from the control id or you might be able to use both in tandem. I believe you can get the x,y position of a control. I have never used it though and a quick google search didn't provide any info. I have had strange behavior in autoit when I called the ubound value like this instead of just saying For $i = 1 To 6. Is the above all your code? Ill download the program and test it. I have to go on a few appointments shortly though so I wont be able to post for several hours in a bit.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

 

From what I'm seeing you are well versed in the concepts of computer logic and how to implement it in autoit. Why don't you just make your own program in autoit that does all of this rather than backpack on someone else's program?

 

I proposed this early on, since I recovered the XML the program downloads as well as the parameters passed to the respective updaters to make them run unattended, but I was discouraged going that route yet. There's a rush. May do it eventually still.

Also do you have a link for this program?

 

https://patchmypc.net/download

.

 

For the toggle issue you can use pixelchecksum instead of selecting the box from the control id or you might be able to use both in tandem

 

It's looking like one of the best/only possible option right now, yes. :-)

 

Is the above all your code?

 

Yeah, I've started working with AutoIt since last weekend. I have experience programming VBScript, VBA, and some VB, and I've built GUIs in other languages, so fortunately I have a little bit of a headstart.

I wish I could DllOpen some DLL and then use semi-internal Windows functions to get a handle to those controls and read their properties, but alas. Google isn't giving me much love in that department. The ClassnameNN matches what was mentioned in the thread I linked; it must be the same problem; I'm wondering what Widget library Patch My PC uses that it thwarts AutoIt.

I have to say though, so far I've fallen in love with AutoIt head over heels. If it becomes even more powerful ... I mean.. just wow. Where has AutoIt been all my life?

Edit: similar issue here, more confirmation:

'?do=embed' frameborder='0' data-embedContent>>

Edited by Michiel

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Give me a bit. I think that the screen resolution of the computer may affect the results of this so Ill make the resolution 1024x768. One thing that I have noticed so far with the program is when I start the program there are check boxes already checked. If I click (Un-Select All) and then click (Select All) It will only click what I assume are all the programs I have installed on my computer in the list. Autoit has an OCR function that was made by one of the users so if all you want is to read what is on the screen then we can use that. I am kind of unsure what you want exactly. I am assuming that you only want to update select things and not others.

Can you be very specific on what you want to happen with your script? There is a way to list all control id's in a window with autoit but I imagine that these will not be universal from computer to computer because different software will be installed on different machines which will affect the results. When you select what you want to update (check stuff) how do you only install/update those?

See -> https://www.autoitscript.com/autoit3/docs/functions/DllOpen.htm and https://www.autoitscript.com/autoit3/docs/functions/DllCall.htm

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

I tried PixelGetColor and PixelChecksum all to no avail, borrowed some of your code, but my code seemed utterly unreliable detecting or checksumming ticked checkboxes.

I've been at it for hours, no success.

Share this post


Link to post
Share on other sites

Partly this can help to recognize more controls (including silverlight)

'?do=embed' frameborder='0' data-embedContent>>

Once you know the area you can count the different colors in that area with PixelGetColor functions.

If not fast enough search for FASM in forums and some examples are there that deal with pixels faster

search for findbmp

'?do=embed' frameborder='0' data-embedContent>>

Share this post


Link to post
Share on other sites

Tell me what you want the script to do in great detail and ill work on it. Im back for the night now.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

What I'm trying to do:

 

Start Patch My PC Portable, then make sure the following items are checked under Common Apps: (Using control names)

  • Chk_AdobeReader
  • Chk_FlashPlugin
  • Chk_FlashPlayer
  • Chk_AdobeAir
  • Chk_AdobeShockwave
  • Chk_MSSilverlight
Then start the update and close the program when done.

 

Bonus:

 

Find out which of those 6 are marked with green text and make sure they are unchecked;

Find out which of those 6 are marked with red text or black text and make sure they are checked;

 

Any others which are checked for whatever reason may stay checked.

 

Of course, there are ways to simply 'do' what Patch My PC does in AutoIt instead, negating the need for Patch My PC altogether; but of course, Patch My PC's strength is that its developer team keeps a close eye on the URL locations where the installers reside and how the installers can be run unattended and silently; as well as comparing those newer versions to currently installed versions and decide whether an update is actually needed or not.

 

@junkew: I'll have some output for you tomorrow. That's some great stuff and a lot to take in.

Edited by Michiel

Share this post


Link to post
Share on other sites

Running into a snag. I found autoit tool (its in your autoit installation directory). It's a tool that shows you the control id's of objects. I am looking into making an array with this information so it can be compared directly with your list instead of using pixelgetcolor or the like. It will be a much better program but itll take a bit more time. I'm working on it.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

@junkew:

Mouse position is retrieved 527-264
At least we have an element [Reader 11.0.09][WindowsForms10.BUTTON.app.0.378734a]

Having the following values for all properties: 
Title is: <Reader 11.0.09>  Class   := <WindowsForms10.BUTTON.app.0.378734a>    controltype:= <UIA_CheckBoxControlTypeId>   ,<50002>    , (0000C352)    479;257;103;18
*** Parent Information top down ***
3: Title is: <Bureaublad>   Class   := <#32769> controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    0;0;1280;800
"Title:=Bureaublad;controltype:=UIA_PaneControlTypeId;class:=#32769"    
2: Title is: <Patch My PC 2.6.0.8>  Class   := <WindowsForms10.Window.8.app.0.378734a>  controltype:= <UIA_WindowControlTypeId> ,<50032>    , (0000C370)    444;142;802;452
"Title:=Patch My PC 2.6.0.8;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.378734a"  
1: Title is: <11 Apps up to date!>  Class   := <WindowsForms10.SysTabControl32.app.0.378734a>   controltype:= <UIA_TabControlTypeId>    ,<50018>    , (0000C362)    471;230;234;336
"Title:=11 Apps up to date!;controltype:=UIA_TabControlTypeId;class:=WindowsForms10.SysTabControl32.app.0.378734a"  
0: Title is: <Common Apps>  Class   := <WindowsForms10.Window.8.app.0.378734a>  controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    475;253;226;309
"Title:=Common Apps;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.378734a"    


;~ *** Standard code ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP2=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Patch My PC 2.6.0.8;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.378734a", $treescope_children)  
_UIA_Action($oP2,"setfocus")
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=11 Apps up to date!;controltype:=UIA_TabControlTypeId;class:=WindowsForms10.SysTabControl32.app.0.378734a", $treescope_children)   
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Common Apps;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.378734a", $treescope_children) 
_UIA_Action($oP0,"setfocus")
_UIA_setVar("Reader11.0.09.mainwindow","title:=Reader 11.0.09;classname:=WindowsForms10.BUTTON.app.0.378734a")
_UIA_action("Reader11.0.09.mainwindow","setfocus")


*** Detailed properties of the highlighted element ***
UIA_title:= <Reader 11.0.09>
UIA_text:= <Reader 11.0.09>
UIA_regexptitle:= <Reader 11.0.09>
UIA_class:= <WindowsForms10.BUTTON.app.0.378734a>
UIA_regexpclass:= <WindowsForms10.BUTTON.app.0.378734a>
UIA_iaccessiblechildId:= <0>
UIA_id:= <Chk_AdobeReader>
UIA_handle:= <66362>
UIA_RuntimeId:= <42;66362>
UIA_BoundingRectangle:= <479;257;103;18>
UIA_ProcessId:= <3016>
UIA_ControlType:= <50002>
UIA_LocalizedControlType:= <selectievakje>
UIA_Name:= <Reader 11.0.09>
UIA_HasKeyboardFocus:= <True>
UIA_IsKeyboardFocusable:= <True>
UIA_IsEnabled:= <True>
UIA_AutomationId:= <Chk_AdobeReader>
UIA_ClassName:= <WindowsForms10.BUTTON.app.0.378734a>
UIA_Culture:= <0>
UIA_IsControlElement:= <True>
UIA_IsContentElement:= <True>
UIA_IsPassword:= <False>
UIA_NativeWindowHandle:= <66362>
UIA_IsOffscreen:= <False>
UIA_Orientation:= <0>
UIA_FrameworkId:= <WinForm>
UIA_IsRequiredForForm:= <False>
UIA_IsDockPatternAvailable:= <False>
UIA_IsExpandCollapsePatternAvailable:= <False>
UIA_IsGridItemPatternAvailable:= <False>
UIA_IsGridPatternAvailable:= <False>
UIA_IsInvokePatternAvailable:= <True>
UIA_IsMultipleViewPatternAvailable:= <False>
UIA_IsRangeValuePatternAvailable:= <False>
UIA_IsScrollPatternAvailable:= <False>
UIA_IsScrollItemPatternAvailable:= <False>
UIA_IsSelectionItemPatternAvailable:= <False>
UIA_IsSelectionPatternAvailable:= <False>
UIA_IsTablePatternAvailable:= <False>
UIA_IsTableItemPatternAvailable:= <False>
UIA_IsTextPatternAvailable:= <False>
UIA_IsTogglePatternAvailable:= <True>
UIA_IsTransformPatternAvailable:= <False>
UIA_IsValuePatternAvailable:= <False>
UIA_IsWindowPatternAvailable:= <False>
UIA_ValueIsReadOnly:= <True>
UIA_RangeValueValue:= <0>
UIA_RangeValueIsReadOnly:= <True>
UIA_RangeValueMinimum:= <0>
UIA_RangeValueMaximum:= <0>
UIA_RangeValueLargeChange:= <0>
UIA_RangeValueSmallChange:= <0>
UIA_ScrollHorizontalScrollPercent:= <0>
UIA_ScrollHorizontalViewSize:= <100>
UIA_ScrollVerticalScrollPercent:= <0>
UIA_ScrollVerticalViewSize:= <100>
UIA_ScrollHorizontallyScrollable:= <False>
UIA_ScrollVerticallyScrollable:= <False>
UIA_SelectionCanSelectMultiple:= <False>
UIA_SelectionIsSelectionRequired:= <False>
UIA_GridRowCount:= <0>
UIA_GridColumnCount:= <0>
UIA_GridItemRow:= <0>
UIA_GridItemColumn:= <0>
UIA_GridItemRowSpan:= <1>
UIA_GridItemColumnSpan:= <1>
UIA_DockDockPosition:= <5>
UIA_ExpandCollapseExpandCollapseState:= <3>
UIA_MultipleViewCurrentView:= <0>
UIA_WindowCanMaximize:= <False>
UIA_WindowCanMinimize:= <False>
UIA_WindowWindowVisualState:= <0>
UIA_WindowWindowInteractionState:= <0>
UIA_WindowIsModal:= <False>
UIA_WindowIsTopmost:= <False>
UIA_SelectionItemIsSelected:= <False>
UIA_TableRowOrColumnMajor:= <2>
UIA_ToggleToggleState:= <0>
UIA_TransformCanMove:= <False>
UIA_TransformCanResize:= <False>
UIA_TransformCanRotate:= <False>
UIA_IsLegacyIAccessiblePatternAvailable:= <True>
UIA_LegacyIAccessibleChildId:= <0>
UIA_LegacyIAccessibleName:= <Reader 11.0.09>
UIA_LegacyIAccessibleRole:= <44>
UIA_LegacyIAccessibleState:= <1048580>
UIA_LegacyIAccessibleDefaultAction:= <Inschakelen>
UIA_IsDataValidForForm:= <False>
UIA_ProviderDescription:= <[pid:3536,hwnd:0x1033A Main:Nested [pid:3016,hwnd:0x1033A Main(parent link):Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]>
UIA_IsItemContainerPatternAvailable:= <False>
UIA_IsVirtualizedItemPatternAvailable:= <False>
UIA_IsSynchronizedInputPatternAvailable:= <False>

@computergroove; that's super nice of you, but... wasn't that sort of what I was doing? Or are you saying you're able to use PixelGetColor and/or PixelChecksum to identify ticked or unticked checkboxes, and you're going to programmatically link that with an array to the control names? Also I thought control ids differ each invocation?

Cheers

Share this post


Link to post
Share on other sites

Run(@ScriptDir & "\PatchMyPC.exe")
Local $hWnd = WinWait("[Class:WindowsForms10.Window.8.app.0.378734a]","",50)
WinSetState($hWnd,"",@SW_MAXIMIZE)
Sleep(1000)
For $i = 1 To 3
    MouseClick("",196,115)
    Sleep(1000)
Next
MouseClick("",864,684)

Got it to work with this. I tried it with several desktop resolutions and it works with all of them. It does not detect the colors. It just clicks unselect all then select all and installs all items not already up to date.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

I assume its this application you try to handle

https://patchmypc.net/download

 
Green = Lastest Application Version Installed
Red = Outdated Application Version Installed
Black = Application Not Currently Installed
 

this property seems to have 2 values (checked/unchecked)

UIA_LegacyIAccessibleState:= <1048576>

or you can use the togglestate property.

I see no properties directly giving you the colors so you probably have to catch the 

UIA_BoundingRectangle:= <479;257;103;18>

and after that with pixelchecksum or bitblt functions count the different color statistics

'?do=embed' frameborder='0' data-embedContent>>

maybe later I will post an example on how to do this with IUIAutomation (work in progress on simplespy so will try to improve spy based on this example)

Edited by junkew

Share this post


Link to post
Share on other sites

I am still working on this. I made this to count the colors within one of the lines of red text:

;get a list of all the colors detected pixel by pixel of an area
#include <array.au3>
#include <FileConstants.au3>
#include <File.au3>

HotKeySet("{PAUSE}","TogglePause")
HotKeySet("{ESC}","Terminate")

Global $Paused
Global $ColorArray[0];placeholder for all the colors
Global $File = @ScriptDir & "\ArrayResults.txt"

Run(@ScriptDir & "\PatchMyPC.exe")
Local $hWnd = WinWait("[Class:WindowsForms10.Window.8.app.0.378734a]","",50)
WinSetState($hWnd,"",@SW_MAXIMIZE)
Sleep(1000)

GetColorList()

Func GetColorList()
    Local $X1 = 267
    Local $Y1 = 107
    Local $X2 = 554
    Local $Y2 = 120
    Local $XLen = $X2 - $X1;Length of the X-axis in the search
    Local $YLen = $Y2 - $Y1;Height of the y-axis in the search
    For $i = 1 To $YLen
        For $j = 1 To $XLen
            ;MouseMove($X1 + 2,$Y1 + 2);Debug line to show where the the script is scanning
            $C1 = PixelGetColor($X1,$Y1)
            $AS = _ArraySearch($ColorArray,$C1)
            If $AS = -1 Then
            _ArrayAdd($ColorArray,$C1)
            EndIf
            ToolTip("Stage " & $i & " of " & $YLen & " and " & $j & " of " & $XLen & " Color Being Scanned: " & $C1,0,0)
            $X1 += 1
        Next
        $X1 = 267
        $Y1 += 1
    Next
    ;_ArrayDisplay($ColorArray)
    _FileWriteFromArray($File,$ColorArray)
    ShellExecute($File)
    ProcessClose($hWnd)
EndFunc

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip("Script is paused",0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Here are the results, there are 39 different colors and white in the text -> '>

I want to work on it more but my brain is tired.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

This one gets rid of the necessity to read colors. It will click the control directly.

;Patchmypc 2.6.0.8
;Script gets the red items on the right snd only selects those items on the left
Run(@ScriptDir & "\PatchMyPC.exe")
Local $hWnd = WinWait("[Class:WindowsForms10.Window.8.app.0.378734a]","",50)
WinSetState($hWnd,"",@SW_MAXIMIZE)
Sleep(1000)
For $i = 1 To 2
    MouseClick("",196,115)
    Sleep(1000)
Next
Local $Array[6] = ["WindowsForms10.BUTTON.app.0.378734a15", _;Acrobat Reader
           "WindowsForms10.BUTTON.app.0.378734a14", _;Flash Plugin
           "WindowsForms10.BUTTON.app.0.378734a13", _;Flash Player
           "WindowsForms10.BUTTON.app.0.378734a12", _;Adobe Air
           "WindowsForms10.BUTTON.app.0.378734a11", _;Shockwave
           "WindowsForms10.BUTTON.app.0.378734a5"]   ;Silverlight

For $i = 0 To UBound($Array) - 1
     ControlClick($hWnd,"",$Array[$i])
Next

MouseClick("",864,684);Click Install and Continue

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Something like this should work (although it lists the items in reverse order)

modules from

?do=embed' frameborder='0' data-embedContent>

;~ *** Standard code maintainable ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

_UIA_setVar("$oP2","Title:=Patch*")
_UIA_setVar("$oP1","Title:=11 Apps up to date!;controltype:=UIA_TabControlTypeId;class:=WindowsForms10.SysTabControl32.app.0.*")
_UIA_setVar("$oP0","Title:=Common Apps;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.*")

_UIA_Action("$oP2","setfocus")
_UIA_Action("$oP1","setfocus")
local $UIA_myObject=_UIA_Action("$oP0","getobject")

;~With a treewalker thru all childs

$UIA_oTW.GetFirstChildElement($UIA_myObject, $UIA_pUIElement)
local $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
local $color
AutoItSetOption ( "PixelCoordMode" ,1)

While IsObj($oUIElement) = True
    local $rectangle = _UIA_getPropertyValue($oUIElement, $UIA_BoundingRectanglePropertyId)
    local $name=_UIA_getPropertyValue($oUIElement, $UIA_NamePropertyId)
    local $t = StringSplit($rectangle, ";")
;~  _UIA_DrawRect($t[1]+16, $t[3] + $t[1], $t[2], $t[4] + $t[2])
;~  _ScreenCapture_Capture($name, $t[1], $t[2], $t[3] + $t[1], $t[4] + $t[2])


; Find a pure green pixel
Local $aCoord = PixelSearch($t[1]+16, $t[2], $t[3] + $t[1], $t[4] + $t[2], 0x006400)
If Not @error Then
    consolewrite("1 X and Y are: " & $aCoord[0] & "," & $aCoord[1])
    $color="green"
else
    ; Find a pure black pixel
    Local $aCoord = PixelSearch($t[1]+16, $t[2], $t[3] + $t[1], $t[4] + $t[2], 0x000000)

    If Not @error Then
        consolewrite("2 X and Y are: " & $aCoord[0] & "," & $aCoord[1])
        $color="black"
    else
        $color="red"
    EndIf
EndIf

    ConsoleWrite("Title is: " & $name & @TAB & "Handle=" & Hex(_UIA_getPropertyValue($oUIElement, $UIA_NativeWindowHandlePropertyId)) & @TAB & "Class=" & _UIA_getPropertyValue($oUIElement, $uia_classnamepropertyid) & @TAB & "Rectangle=" & $rectangle & @tab & $color & @CRLF)


    $UIA_oTW.GetNextSiblingElement($oUIElement, $UIA_pUIElement)
    $oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
WEnd
Edited by junkew

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0