The AutoIt PixelSearch Function is used to search a region of the screen for a pixel with a given color value, or a variation thereof.
PixelSearch either returns a two element array containing the coordinates of the pixel, or sets @error to 1 if color is not found.
PixelSearch is generally pretty fast, but if you think its to slow, narrowing the search area may help increase the performance.
|pixels||Left coordinate of rectangle.|
|pixels||Top coordinate of rectangle.|
|pixels||Right coordinate of rectangle.|
|pixels||Bottom coordinate of rectangle.|
|color||Colour value of pixel to find (in decimal or hex).|
|shade-variation [optional]||A value between 0-255. This parameter allows to search for variations of the color provided. If provided, the number will search for a variation within both the Red, Geen, and Blue values of the color.|
|step [optional]||A value larger then 1 will skip pixels, instead of searching each pixel. Effects the speed of the search.|
|hwnd [optional]||Window handle.|
Looks for a pure Red Pixel, in the region 0,0 (Start) - 100,200 (end).
$coord = PixelSearch(0, 0, 100, 200, 0xFF0000) If Not @error Then MsgBox(0, "X and Y are:", $coord & "," & $coord) EndIf
If you want to search for variations, then simply add the next parameter.
$coord = PixelSearch(0, 0, 100, 200, 0xFF0000, 5) If Not @error Then MsgBox(0, "X and Y are:", $coord & "," & $coord) EndIf
To click the returned coordinates, use something like the below.
$coord = PixelSearch(0, 0, 100, 200, 0xFF0000, 5) If Not @error Then MouseClick("primary", $coord, $coord, 1, 0) EndIf
If you want to click somewhere near where the color was found, say above or below, than simply add the offset to the coordinates. Just be careful that you don't attempt to click outside the screen. The below will click 15 pixels above the located color:
$coord = PixelSearch(0, 15, 100, 200, 0xFF0000) If Not @error Then MouseClick("primary", $coord, $coord-15, 1) EndIf
- PixelSearch - autoitscript.com