Skip to content

Instantly share code, notes, and snippets.

@Lvl4Sword
Created March 31, 2019 16:56
Show Gist options
  • Save Lvl4Sword/dca71ab382515944916c07a86a62c2aa to your computer and use it in GitHub Desktop.
Save Lvl4Sword/dca71ab382515944916c07a86a62c2aa to your computer and use it in GitHub Desktop.
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