Alexxander Posted September 7, 2013 Share Posted September 7, 2013 (edited) 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 September 7, 2013 by alexander95 Link to comment Share on other sites More sharing options...
DW1 Posted September 7, 2013 Share Posted September 7, 2013 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. AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Alexxander Posted September 7, 2013 Author Share Posted September 7, 2013 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" Link to comment Share on other sites More sharing options...
DW1 Posted September 7, 2013 Share Posted September 7, 2013 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. Alexxander 1 AutoIt3 Online Help Link to comment Share on other sites More sharing options...
DW1 Posted September 7, 2013 Share Posted September 7, 2013 (edited) 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 September 7, 2013 by danwilli Alexxander 1 AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Alexxander Posted September 7, 2013 Author Share Posted September 7, 2013 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 More sharing options...
FireFox Posted September 7, 2013 Share Posted September 7, 2013 What is the "box", a window control?There may be more reliable ways to automate what you're trying to do.Br, FireFox. Link to comment Share on other sites More sharing options...
DW1 Posted September 7, 2013 Share Posted September 7, 2013 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. Alexxander 1 AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Kidney Posted September 7, 2013 Share Posted September 7, 2013 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now