Code: Select all
Loop
PixelSearch, Px, Py, 835, 885, 835, 855, 0x00F26F, Fast
Sleep 500
Until, ErrorLevel = 0
Code: Select all
Loop
PixelSearch, Px, Py, 835, 885, 835, 855, 0x00F26F, Fast
Sleep 500
Until, ErrorLevel = 0
https://www.autohotkey.com/docs/commands/Until.htm wrote:Code: Select all
Loop { ... } Until Expression
Ahh, okay that makes sense. Thanks!gregster wrote: ↑04 Jul 2022, 18:40In AHK, you would group multiple statements together by using braces { } (aka blocks); indenting has no effect in AHK, it's just a visual helper.
You can only omit braces if only a single dependent line is following a statement like loop, if, while, ...
https://www.autohotkey.com/docs/commands/Until.htm wrote:Code: Select all
Loop { ... } Until Expression
This means, if you don't want to use variation, just leave that (optional) parameter blank:https://www.autohotkey.com/docs/commands/PixelSearch.htm wrote:Code: Select all
PixelSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ColorID [, Variation, Mode]
Code: Select all
PixelSearch, Px, Py, 835, 885, 835, 855, 0x00F26F, , Fast
Code: Select all
WaitForColor(90, 110, 0xF0F0F0) ; Go to function WaitForColor to wait for color to change. (X, Y, color)
MsgBox,0,,The color was found.
Exitapp
;*************** Wait for a pixel to be a Color ********************************
WaitForColor(pX, pY, pC) ; Start of function WaitForColor. Gets X and Y coordinates and color from the sending line.
{ ; Needed at the start of the function
Loop ; Loop to wait for color to change
{ ; Needed at the start of the loop
PixelGetColor, color, %pX%, %pY%, RGB ; Get the color of the pixel at the specified location. Remove the RGB if not using RGB
If color = %pC% ; Compare the color of that pixel with the specified color.
break ; If that color matches, break
Sleep 50 ; Reduce CPU usage so its not looking every millisecond.
} ; Needed at the end of the loop
} ; Needed at the end of the function
;To have it wait until the pixel is not the color you specified, change the line in the loop to If color != %pC%
Code: Select all
If WaitForColorArea(175, 126, 195, 148, 0xFFE792, 5, 50, FoundX, FoundY)
; (x1, y1, x2, y2, Color, variation of color, timeout, FoundX, FoundY)
; Timeout is in 10th of a second. for 1 second enter 10, for 10 seconds enter 100
MsgBoX,0,,Color found
Else
MsgBox,0,,Color NOT found
Exitapp
;*************** Wait for a color in an area then return the coordinates *********************
WaitForColorArea(X1, Y1, X2, Y2, pC, V, T=10000, ByRef FoundX=0, ByRef FoundY=0)
; Start of function WaitForColorArea. Gets X and Y coordinates, color and timeout time from the sending line.
;If no time specified in sending line, timeout is set to 10000 which is 1000 seconds (16min 40 seconds)
{ ; Needed at the start of the function
Loop, %T% ; Loop the number of times specified in the timeout time.
{ ; Needed at the start of the loop
PixelSearch, FoundX, FoundY, %X1%, %Y1%, %X2%, %Y2%, %PC%, %V%, Fast RGB ; You can remove the RGB if not using RGB.
If (Errorlevel = 0) ; Once the color is found...
Return True ; ...Return to caller with True
Sleep 100 ; Reduce CPU usage so its not looking every millisecond.
} ; Needed at the end of the loop
Return False ; If the color was not found after the specified time, return false
} ; Needed at the end of the function
; To make it search for any color other than the one you specify, put a ! in font of the color in the sending statement. ie !0xFFE792.
; Then if a color other than the one you specify is found, it will return True and do the lines under the If command.
; And if only the color you specify is found, it will time out and return False and do the lines under the Else command.
; To reverse it so the code after the sending statement is if the color is not found, and the code after the Else is if the color is found, change the sending statement to 'If Not WaitForColorArea...'