Search code examples
automationrpag1ant

Why position of mouse always take absolute position and colour at position command always return relative colour of window?


I want to take the colour of the window at some position, I had tried to use both absolute position and relative position of the mouse(when the question dialogue box pops up) and with both the arguments of colour position relative true and false but with every condition it always takes the absolute position of mouse and return the colour of the relative window.

 color position 762⫽485 relative false
 dialog ♥result

As g1ant window is white it returns FFFFFF but my desktop is red.


Solution

  • As you have noticed, the robot is getting the colour of the G1ANT.Robot window and not the desktop. According to the manual:

    The color command retrieves the red, green and blue (RGB) color values of the pixel at the specified coordinates

    And about the relative argument:

    position needs a value representing pixel coordinates and relative defines if these coordinates are relative to the upper left corner of the active window (by default) or absolute on the screen (also measured from its upper left corner).

    So absolute position means that wherever the window is, the colour will be get relative to the top left corner of the screen. relative position means that the colour will be get relative to the top left corner of the active window.

    In your example it doesn't matter if your desktop is red because, I assume, G1ANT.Robot is focused when you launch your script.

    You can either:

    1. Use the WIN+D shortcut which will minimize all opened windows (show desktop):
    color position 762⫽485 relative false
    keyboard ⋘WIN+D⋙
    dialog ♥result
    
    1. Leave the script as it is but move the G1ANT.Robot window to some position where it doesn't cover the 762⫽485 position that you want to get the colour from.