asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.24k forks source link

pyautogui.cposition() xy & rgb color returned #702

Open JayRizzo opened 2 years ago

JayRizzo commented 2 years ago

Returns position with RGB & Alpha as two tuples.

I figured it would be a nice to have. Currently Tested only on Mac.

@asweigart let me know if you want me to make any adjustments to this branch.

import pyautogui

((currentMouseX, currentMouseY), (red, green, blue, alpha)) = pyautogui.cposition() 
# Get the current XY position of the mouse with the color RGBA.

((currentMouseX, currentMouseY), (red, green, blue, alpha)) = pyautogui.cposition(1314, 345) 
# Or Get a specific XY position of the mouse with the color RGBA.

currentMouseX, currentMouseY
#    1314, 345
red, green, blue, alpha
#    45, 163, 52, 255  # osx
#    45, 163, 52, None # win