Get Pixel Color
Use the Get Pixel Color option to obtain the pixel color underneath the mouse pointer. The pixel color is assigned a numeric value by Windows, normally 6 – 8 digits in length. This numeric value is then saved to an Integer variable such as N[1]. For details about colors see How colors are displayed.
This command can be used for a variety of tasks. For example, use this command to determine if a check box has been checked or not. Or for a particularly difficult timing problem, the Get Pixel Color command may be the solution.
Script Editor > Expand System Category > Get Pixel Color
Options
First select the option for determining the location of the pixel, either beneath the mouse or using specific coordinates.
Beneath the Mouse
This option obtains the color of the pixel located directly underneath the mouse pointer. The pixel color is obtained wherever the mouse cursor is located at the time this command takes place during the macro.
Specific Coordinates
With this option assign the specific mouse coordinates based on the active window or the entire screen. Insert the X and Y coordinates of the pixel to find.
Relative to Screen
Relative to Screen instructs the macro to move the mouse cursor relative to its position on the computer screen. Use the "Screen Coordinates" numbers from the Mouse Locator with this option.
Relative to Window
This option instructs the macro to move the mouse cursor relative to its position within the window that is active or has focus. Use the "Active Window" numbers from the Mouse Locator with this option.
Launch Mouse Locator
The mouse locator is an easy way to obtain the pixel coordinates when using the Specific Coordinates option. If the Mouse Locator window pops up in an area of the screen that covers important data, click on the window, hold the left mouse button down on the blue bar at the top of the window and drag to another location. See the Launch Mouse Locator topic for details on use.
Destination
Assign the pixel color obtained to a variable.
Sample Macro - Get Pixel
Here's an example of how this command could be used. Let's say that there is a web site that uses two alternating graphical images, one red and the other green. We want to determine which image is displayed and take appropriate action based on the results.
The first step is to load the web page. Use the Get Pixel Color command and select the At Specific Coordinates option, Relative to Screen.
With this information we can build the rest of the macro. The macro inserts a password if the image is red. If the image is not red (because the green image is currently displayed), it opens a new web page.
Macro Script Get Pixel If Variable %N[1]% = 255 Text Type: <TAB> 123xyz Else Web Site: https://www.macros.com End If
The pixel color for red is 255. This is the value we wrote down on the piece of paper to use with the If Variable command. So what we have done is use the If Variable command, stating if variable N[1] (what we assigned to the pixel color) equals a value of 255, then press a Tab and type in the password of 123xyz.
If the red graphical image is not present when the macro is run, then N[1] will have a different value (a value for green). It will not match the value of 255 in the If Variable statement. The Text Type command is skipped and the www.macros.com web page is launched instead. |