Sign in to follow this  
Followers 0
hero88

Waiting for a pixel to change colour

9 posts in this topic

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

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Doublepost

Edited by hero88

Share this post


Link to post
Share on other sites

It works for me when I insert the Sleep(99) statement.

So thanks a lot, I will remember that, it was not something I would i found out by myself :)

Share this post


Link to post
Share on other sites

Glad that it is working for you.

You can take the Sleep down to about 10 milliseconds if need be...

99 is just what I used because I was already on the "(" key.

Enjoy AutoIt.


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

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

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