Jump to content
Sign in to follow this  
SkyDancer

PixelGetColor makes comparing time with random delay all the time

Recommended Posts

Const $pixel_check_x = 1030
Const $pixel_check_y = 409
Const $pixel_check_color = 13093063
Const $send_delay_ms = 520


Do
    $pixel = PixelGetColor($pixel_check_x, $pixel_check_y)
Until $pixel = $pixel_check_color

Sleep($send_delay_ms)

Send("{SPACE}")

Exit

I have this code but delay is always random time after color matched, how to make color waiting with a static time then make some static delay and then pres Space button? Thank you.

Share this post


Link to post
Share on other sites
5 minutes ago, Nine said:

It is your loop that takes a random time to find the right color. IMO.

Exectly. I need to search color with a static time. Is it posible to do it in AutoIt?

Share this post


Link to post
Share on other sites

But how to wait for specific lolor then? I need to wait till one pixel on the screen changed the color then I need static delay and then Press Space button. So the basic question is how to wait for the pixel color changet with a static time, the pixel position is always static so it has to be static time for search it.

Share this post


Link to post
Share on other sites
4 minutes ago, SkyDancer said:

I need to wait till one pixel on the screen changed the color

If that change happens randomly, it will be random, you cannot have both.  And may I ask what kind of application you are trying to automate ?  Could help if we know what you are attempting to do 

Share this post


Link to post
Share on other sites

Im trying to make a unit test for my own web application. And I know the pixel color time is random but after pixel changed, from this moment next steps have to be with a static time but seems like the time for pixel search is random, but it has to be static since the pixel coordinates are always the same or I understand pixel search algorithm wrong?

Share this post


Link to post
Share on other sites

Try this :

Const $pixel_check_x = 1030
Const $pixel_check_y = 409
Const $pixel_check_color = 13093063
Const $send_delay_ms = 520

$timer = TimerInit ()
Do
    $pixel = PixelGetColor($pixel_check_x, $pixel_check_y)
Until $pixel = $pixel_check_color

Sleep($send_delay_ms - TimerDiff($Timer))

Send("{SPACE}")

It will be static unless the pixel doesn't show before end of delay.  But you can manage that, right ?

Share this post


Link to post
Share on other sites

Made this function and modified it

Func _ColourReturn($x, $y, $colour)
    If PixelGetColor($x, $y, $hWnd) = $colour Then Return True
    If PixelGetColor($x, $y, $hWnd) <> $colour Then Return False
EndFunc

Try this out. Just set a sleep delay in the do loop

 

Const $pixel_check_x = 1030
Const $pixel_check_y = 409
Const $pixel_check_color = 13093063
Const $send_delay_ms = 520
Const $iStaticSleep = xxxxxxxxxxxxxxxx


Do
    Sleep($iStaticSleep)
Until _ColourReturn($pixel_check_x, pixel_check_y, $pixel_check_color)

Sleep($send_delay_ms)

Send("{SPACE}")

Exit

Func _ColourReturn($x, $y, $colour)
    If PixelGetColor($x, $y) = $colour Then Return True
    If PixelGetColor($x, $y) <> $colour Then Return False
EndFunc

 

Share this post


Link to post
Share on other sites

It'll just loop until the color is found, just like the code in the first post, they seem the same to me.
 

Quote

 

from this moment next steps have to be with a static time but seems like the time for pixel search is random,

but it has to be static since the pixel coordinates are always the same

 

Well, in theory yes, since you give the coordinates, it should take the same time, every time, but probably because of the cpu load or other factors, there may be a small random delay each time, you have to code counting with it.


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
18 hours ago, careca said:

but probably because of the cpu load or other factors, there may be a small random delay each time, you have to code counting with it.

That is not a small rng time, its around 50-200ms, can it be cuz I run script from IDE? Cuz tbh I didn't try to compile and use it as exe script file...

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...