PixelGetColor()

Auto Hotkey

PixelGetColor

Retrieves the color of the pixel at the specified x,y coordinates.

OutputVar := PixelGetColor(X, Y , Alt|Slow)
Function Example: color := PixelGetColor(100,200)

Parameters

OutputVar

The name of the variable in which to store the color ID in hexadecimal red-green-blue (RGB) format. For example, the color purple is defined 0x800080 because it has an intensity of 80 for its blue and red components but an intensity of 00 for its green component.

X, Y

The X and Y coordinates of the pixel. Coordinates are relative to the active window unless CoordMode was used to change that.

Alt|Slow

This parameter may contain zero or more of the following words. If more than one word is present, separate each from the next with a space (e.g. Alt Slow).

Alt: Uses an alternate method to retrieve the color, which should be used when the normal method produces invalid or inaccurate colors for a particular type of window. This method is about 10% slower than the normal method.

Slow: Uses a more elaborate method to retrieve the color, which may work in certain full-screen applications when the other methods fail. This method is about three times slower than the normal method. Note: Slow takes precedence over Alt, so there is no need to specify Alt in this case.

ErrorLevel

ErrorLevel is set to 1 if there was a problem or 0 otherwise.

Remarks

The pixel must be visible; in other words, it is not possible to retrieve the pixel color of a window hidden behind another window. By contrast, pixels beneath the mouse cursor can usually be detected. The exception to this is game cursors, which in most cases will hide any pixels beneath them.

Use Window Spy (available in tray icon menu) or the example at the bottom of this page to determine the colors currently on the screen.

Known limitations:

  • A window that is partially transparent or that has one of its colors marked invisible (WinSetTransColor) typically yields colors for the window behind itself rather than its own.
  • PixelGetColor might not produce accurate results for certain applications. If this occurs, try specifying the word Alt or Slow in the last parameter.

Related

PixelSearch, ImageSearch, CoordMode, MouseGetPos

Example

^!z::  ; Control+Alt+Z hotkey.
MouseGetPos, MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%
MsgBox The color at the current cursor position is %color%.
return