Last active
December 29, 2022 15:29
-
-
Save androiddevnotes/065c071c329bbff58b0c2f5b410faae0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# pip install pyautogui | |
# Reference: https://pyautogui.readthedocs.io/en/latest/mouse.html | |
import pyautogui, sys, time | |
# Set the timer interval (in seconds) | |
interval = 0 | |
print('Press Ctrl-C to quit.') | |
try: | |
# Start the timer | |
start_time = time.perf_counter() | |
while True: | |
# Check the mouse position | |
x, y = pyautogui.position() | |
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4) | |
# Print the position string | |
print(positionStr, end='\r') | |
# Wait until the timer interval has elapsed | |
elapsed_time = time.perf_counter() - start_time | |
if elapsed_time < interval: | |
time.sleep(interval - elapsed_time) | |
start_time = time.perf_counter() | |
except KeyboardInterrupt: | |
# Handle Ctrl-C interrupt | |
print('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment