Jump to content

pixel search -need help-


Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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  

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...