Jump to content
Sign in to follow this  
Alexxander

pixel search -need help-

Recommended Posts

Alexxander

hi al

i'm trying to make a script that search a specified box on the screen for a pixel if found then open try.exe then sleep 30 sec , after sleeping 30 sec search again , if not found then keep trying

 

so whenever the pixel is in the box: "try.exe" is running and when the pixel in not in the box try.exe is closed

but when finding the pixel it sleeps 30 sec then search again and keep doing this forever

 

i think my fault is in the while loop

while 1

if PixelSearch(289, 261, 389, 292, 8230822) <> 0 Then ShellExecute("c:\auto\try.exe")
if PixelSearch(289, 261, 389, 292, 8230822) <> 0 Then Sleep(30000)
if PixelSearch(289, 261, 389, 292, 8230822) = 0 Then ProcessClose("try.exe")

WEnd

any ideas how to fix it ?

Edited by alexander95

Share this post


Link to post
Share on other sites
DW1

First, look at the expected return from PixelSearch as it's not what you think it is in that script.

Second, there are better ways of making the loop, but first correct it so that you are at least using PixelSearch correctly.

Share this post


Link to post
Share on other sites
Alexxander
danwilli

 

thank for fast replay bro 

i used this to know the return value

$pix = PixelSearch(289, 261, 389, 292, 8230822)
msgbox(0,"",$pix)

when autoit find the pixel i get an empty msgbox

when autoit cant find the pixel i get msg box written in it "0"


Share this post


Link to post
Share on other sites
DW1

PixelSearch

Return Value

Success: Returns a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y).

Failure: Sets @error to 1 if color is not found.

  • Like 1

Share this post


Link to post
Share on other sites
DW1

Something like this I would think:

Local $iDelay = 500, $iPid
While 1
    PixelSearch(289, 261, 389, 292, 8230822)
    If Not @error Then ;If the pixel search found the pixel
        $iPid = Run("c:\auto\try.exe") ;Run the application and note the process ID
        While 1 ;Loop while the process still exists and the pixel search is still true
            PixelSearch(289, 261, 389, 292, 8230822)
            If @error Then ExitLoop ;Exit the loop since the pixelsearch failed
            If Not ProcessExists($iPid) Then ExitLoop ;Exit the loop since the process no longer exists
            Sleep($iDelay) ;A delay for CPU usage sake
        WEnd
        ProcessClose($iPid) ;Close the process (doesn't matter if it is already closed)
    EndIf
    Sleep($iDelay) ;A delay for CPU usage sake
WEnd

Not sure what Try.exe does, so in my above example we will start searching for the pixel again if try.exe no longer exists, or if the pixel is no longer found and we kill try.exe because of that.

Edited by danwilli
  • Like 1

Share this post


Link to post
Share on other sites
Alexxander

Something like this I would think:

Local $iDelay = 500, $iPid
While 1
    PixelSearch(289, 261, 389, 292, 8230822)
    If Not @error Then ;If the pixel search found the pixel
        $iPid = Run("c:\auto\try.exe") ;Run the application and note the process ID
        While 1 ;Loop while the process still exists and the pixel search is still true
            PixelSearch(289, 261, 389, 292, 8230822)
            If @error Then ExitLoop ;Exit the loop since the pixelsearch failed
            If Not ProcessExists($iPid) Then ExitLoop ;Exit the loop since the process no longer exists
            Sleep($iDelay) ;A delay for CPU usage sake
        WEnd
        ProcessClose($iPid) ;Close the process (doesn't matter if it is already closed)
    EndIf
    Sleep($iDelay) ;A delay for CPU usage sake
WEnd

Not sure what Try.exe does, so in my above example we will start searching for the pixel again if try.exe no longer exists, or if the pixel is no longer found and we kill try.exe because of that.

 

seem awesome code but i cant get it to work i don't know why !

thanks anyway  


Share this post


Link to post
Share on other sites
FireFox

What is the "box", a window control?

There may be more reliable ways to automate what you're trying to do.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
DW1

seem awesome code but i cant get it to work i don't know why !

thanks anyway  

Tested and working for me (with a different pixel search).  Perhaps your pixel search is bad.

  • Like 1

Share this post


Link to post
Share on other sites
Kidney

you could also try _ImageSearch. anything i cant get a controller for i just use that. i was using pixelsearch for awhile but it was horribly inaccurate. Thats my suggestion tho.

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  

×