Created
March 31, 2019 16:56
-
-
Save Lvl4Sword/dca71ab382515944916c07a86a62c2aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import pyautogui | |
import pyscreeze | |
import sys | |
def MousePosition(): | |
"""This function is meant to be run from the command line. It will | |
automatically display the location and RGB of the mouse cursor.""" | |
print('Press Ctrl-C to quit.') | |
try: | |
while True: | |
# Get and print the mouse coordinates. | |
x, y = pyautogui.position() | |
pixelColor = pyscreeze.screenshot().getpixel((x, y)) | |
positionStr = 'X: {0:4} Y: {1:4} RGB: ({2:3}, {3:3}, {4:3})'.format(x, y, pixelColor[0], pixelColor[1], pixelColor[2]) | |
sys.stdout.write(positionStr) | |
sys.stdout.write('\b' * len(positionStr)) | |
sys.stdout.flush() | |
except KeyboardInterrupt: | |
sys.stdout.write('\n') | |
sys.stdout.flush() | |
MousePosition() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment