From 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef Mon Sep 17 00:00:00 2001 From: mlot Date: Fri, 6 Jun 2025 13:40:57 -0400 Subject: initial commit for archiving --- Chap18ProjExtendMouseNow.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Chap18ProjExtendMouseNow.py (limited to 'Chap18ProjExtendMouseNow.py') diff --git a/Chap18ProjExtendMouseNow.py b/Chap18ProjExtendMouseNow.py new file mode 100644 index 0000000..3c69dd3 --- /dev/null +++ b/Chap18ProjExtendMouseNow.py @@ -0,0 +1,20 @@ +#! python3 + +# Chapter 18 Project Extended Mouse Now +# Displays the mouse cursor's current postion + +import pyautogui + +print('Press Ctrl-C to quit.') +try: + while True: + x, y = pyautogui.position() + positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4) + pixelColor = pyautogui.screenshot().getpixel((x,y)) + positionStr += ' RGB: (' + str(pixelColor[0]).rjust(3) + positionStr += ', ' + str(pixelColor[1]).rjust(3) + positionStr += ', ' + str(pixelColor[2]).rjust(3) + ')' + print(positionStr, end='') + print('\b' * len(positionStr), end='', flush=True) +except KeyboardInterrupt: + print('\nDone.') -- cgit