Jump to content

Recommended Posts

Posted

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

Posted

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]

Posted

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.

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]

Posted

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]

Posted

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 :)

Posted

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]

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
  • Recently Browsing   0 members

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