Jump to content

Waiting for a pixel to change colour


Recommended Posts

Hi

I have written a program to automate something and I would like for the script to wait until a specific buttons is clickable, I have the button colour and the coords, so I have created the following function, which I would think waits until a pixel is a specific colour, but it doesn't seem to work.

If I just run the script, it doesn't click on the button which it should do directly after the function call, if on the other hand I insert this "MsgBox(0,"The decimal color is", $colour)" and only click ok on it when the button has turned clickable then it works ok.

So if anyone can see if this should work or not, I would appreciate it.

Func _WaitForPixelChange($colourvalue,$xcoord,$ycoord)

Do

$colour = PixelGetColor ( $xcoord, $ycoord)

until $colour = $colourvalue

EndFunc

Link to comment
Share on other sites

Welcome to the forum.

When you call the function, is $colourvalue a decimal representation of the color of interest? Also, you might want a small sleep in your Do/Until loop to prevent 100% CPU usage.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Welcome to the forum.

When you call the function, is $colourvalue a decimal representation of the color of interest? Also, you might want a small sleep in your Do/Until loop to prevent 100% CPU usage.

Thank you.

Yes it is a decimal value, good idea I will do that.

Link to comment
Share on other sites

This worked fine for me.

_WaitForPixelChange(255, 1145, 886)

MsgBox(0, "", "")

Func _WaitForPixelChange($colourvalue, $xcoord, $ycoord)
    Do
        Sleep(99)
        $colour = PixelGetColor($xcoord, $ycoord)
    Until $colour = $colourvalue
EndFunc   ;==>_WaitForPixelChange
Are you sure that you have the correct x, y locations?

They can be with respect to the screen, window, client...

Edit: See the AutoIt "Active Window Info" tool:

Options > Coord Mode > ...

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

This also works - but I changed the coords to the active window:

Opt("PixelCoordMode", 0)

_WaitForPixelChange(255, 1145, 12)

MsgBox(0, "", "")

Func _WaitForPixelChange($colourvalue, $xcoord, $ycoord)
    Do
        Sleep(99)
        $colour = PixelGetColor($xcoord, $ycoord)
    Until $colour = $colourvalue
EndFunc   ;==>_WaitForPixelChange

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

I have written a program to automate something and I would like for the script to wait until a specific buttons is clickable

You can do it more effective/reliable way :) :

; wait until Button1 is enabled
While ControlCommand("Your window title", "Your window text", "Button1","IsEnabled","") = 0
    Sleep(50)
WEnd
Edited by Zedna
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...