For greater flexibility, you can use a functionized version of
PixelSearch. For instance:
Code:
c = 0xded9d2
c2 = 0xa16e09
c3 = 0xffe3d0
#g::
If ( pos := PixelSearch((qc := C) . " 3 fast", x1, y1, x2, y2 ) )
|| ( pos := PixelSearch((qc := C2) . " 3 fast", x1, y1, x2, y2 ) )
|| ( pos := PixelSearch((qc := C3) . " 3 fast", x1, y1, x2, y2 ) )
{
Click, % ((pos >> 16) - 32768) . " " . ((pos & 65535) - 32768)
tooltip, The color %qc% was clicked.
}
return
; Functionized pixelsearch, version 5.2
; use parameter 1 for the color, variance, fast, and rgb
; options, seperated by a literal space or a literal comma
; example: result := PixelSearch("0x123456, 7, fast, rgb", 15, 20, 25, 30)
; Additionally, the option 'screen' can be used when
; [CoordMode, Pixel, Screen] is in effect to change the default
; search bounds to match the screen, rather than the active window.
; The return value is zero if and only if the pixel was not found
; if there was a problem, the return value is null
; if the pixel was found, the return value is the encoded coordinates
; use FoundX := (result >> 16) - 32768 ; or (result // 0x10000) - 0x8000
; and FoundY := (result & 65535) - 32768 ; or Mod(result, 0x10000) - 0x8000
; The following example will move the mouse cursor to the first found
; white pixel in the current active window:
; If (coords := PixelSearch("0xFFFFFF fast"))
; MouseMove, % (coords >> 16) - 32768, % (coords & 65535) - 32768, 5
;
PixelSearch(color = 0, left = "", top = "", right = "", bottom = "")
{
var := 0
If (left = "" || top = "")
WinGetPos,,, Width, Height, A
If InStr(Color, "fast")
options = "Fast"
If InStr(Color, "RGB")
options .= (options ? " " : "") "RGB"
If InStr(Color, "screen")
width := A_ScreenWidth, height := A_ScreenHeight
Loop, Parse, color, `, %A_Tab%
{
IfEqual, col,, SetEnv, col, % SubStr(A_LoopField,1,8)
else If A_LoopField IS Number
var := Round(A_LoopField)
break
}
IfEqual, right,, SetEnv, right, % left="" ? width + (left:=0) : left
IfEqual, bottom,, SetEnv, bottom, % top="" ? height + (top:=0) : top
PixelSearch, ox, oy, left, top, right, bottom, %col%, %var%, %options%
IfEqual, ErrorLevel, 0, return ((ox+32768) << 16) | (oy + 32768)
return Errorlevel = 2 ? "" : 0
}
Such a function can be easily incorporated into expressions and
if statements because its return value is non-false when it finds the color. This is only one variation of many different functions made for this command. Try searching the forums for some other ones.