Sign in to follow this  
Followers 0
bi0hazrd

Pixelgetcolor() Problems

9 posts in this topic

I have a piece of code that is checking to see if a checkmark image is toggled when given a command.

Using the following code, I receive the same value (0xC0C0C0) from the message box. By uncommenting the MouseMove command, I receive the correct value (either 0x00000 for the checkmark or 0xB5BCD1 if the checkmark doesn't exist)

I'm using the default options for PixelCoordMode and MouseCoordMode.

;MouseMove(270,205)
$checkmark = PixelGetColor(270,205)
    
Sleep(1000)
MsgBox(0,"Checkmark",$checkmark)

A little more detail. The checkmark I'm looking for is for a menu item on a standard menu toolbar. The 0xC0C0C0 value I receive when the mouse isn't moved is the colour the pixel would be if the menu item wasn't displayed. I've verified this by changing the colour of this background pixel.

Further down, I have the following code that checks if the checkmark was toggled correctly. Regardless of whether the MouseMove command is commented or not, I always get the background colour pixel, not the pixel colour of the menu item, even though it is displayed.

If $checkmark == 0 Then ;Checkmark previously existed
    MouseMove(270,205)
    $pixColour = PixelGetColor(270,205)
    Sleep(1000)
    MsgBox(0,"PixelColor for 0",$pixColour)
    If Not (PixelGetColor(270,205) == 11910353) Then
        $result = 0
    EndIf
ElseIf $checkmark == 11910353 Then ;Checkmark previously did not exist
    MouseMove(270,205)
    $pixColour = PixelGetColor(270,205)
    Sleep(1000)
    MsgBox(0,"PixelColor for 11910353",$pixColour)
    If Not (PixelGetColor(270,205) == 0) Then
        $result = 0
    EndIf
Else
    $result = 0
EndIf

I thought at first it might have been a timing issue and that the msgbox was appearing too quickly (and thus causing the menu item to disappear), so I put in the sleep. I've tried both 1000ms and 2000ms, but it hasn't made a difference.

Share this post


Link to post
Share on other sites



Have you verified with the AutoIt Window Info tool that this checkbox isn't an actual control?

Share this post


Link to post
Share on other sites

What's your PixelCoordMode set too... and are you sure the window has focus?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Have you verified with the AutoIt Window Info tool that this checkbox isn't an actual control?

Yes I have. The entire menu item, including all submenu items and checkboxes all have the same control id and classname.

But as you'll notice in the latter part of my code, when I call GetPixelColor() again, even with the mouse over the area where the checkbox is located, it returns the background colour. This leads me to believe that it's not a focus issue.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

What's your PixelCoordMode set too... and are you sure the window has focus?

I don't explicitly set it anywhere, so it should be the default (absolute screen coordinates). The main issue I'm having is the differences in behaviour from the first code segment and the second code segment. In the first case, the correct value is returned (only if the MouseMove command is called), in the second case, an incorrect value is returned regardless.

Here is the code that is between the first and second blocks of code in my original post.

; This toggles the checkmark
Send("!e")
Sleep(1000)
Send("f")
Sleep(1000)
Send("s")
Sleep(1000)

; This displays the menu item again
Send("!e")
Sleep(1000)
Send("f")
Edited by bi0hazrd

Share this post


Link to post
Share on other sites

I've found a workaround to my problem, but I would still like to have a better understanding of why this behaviour is happening in the first place.

; NEED TO MOVE THE MOUSE OFF THE MENU ITEM HERE
If $checkmark == 0 Then;Checkmark previously existed
    MouseMove(270,205)
    $pixColour = PixelGetColor(270,205)
    Sleep(1000)
    MsgBox(0,"PixelColor for 0",$pixColour)
    If Not (PixelGetColor(270,205) == 11910353) Then
        $result = 0
    EndIf
ElseIf $checkmark == 11910353 Then;Checkmark previously did not exist
    MouseMove(270,205)
    $pixColour = PixelGetColor(270,205)
    Sleep(1000)
    MsgBox(0,"PixelColor for 11910353",$pixColour)
    If Not (PixelGetColor(270,205) == 0) Then
        $result = 0
    EndIf
Else
    $result = 0
EndIf

For some reason, PixelGetColor() only gets the correct value if the mouse moves over the menu item. Selecting the menu item using accelerator keys isn't sufficient to get the correct value, so instead it returns the colour of the pixel underneath the menu item, even though the menu item is visible.

Share this post


Link to post
Share on other sites

My assumption is that the menu color changes with a mouse over... try writing a script to get the color without the mouse over it rather than using the AutoInfo tool.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

My assumption is that the menu color changes with a mouse over... try writing a script to get the color without the mouse over it rather than using the AutoInfo tool.

It does. But it also changes when using the accelerator keys. Even if it didn't, the base menu colour is not the value being returned either. I would expect that if a menu item is occupying the pixel I'm looking at, that the colour of menu would be returned, not the colour of the pixel behind the menu, regardless of how I've selected the menu item.

Share this post


Link to post
Share on other sites

I found out what the problem was. It was a timing issue. I wasn't giving enough time for the menu to appear between invoking the menu and checking for the pixel colour. The mouse move provided this brief pause, but I've since replaced it with a 1 second sleep and its working fine.

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