Skip to content

Instantly share code, notes, and snippets.

@androiddevnotes
Last active December 29, 2022 15:29
Show Gist options
  • Save androiddevnotes/065c071c329bbff58b0c2f5b410faae0 to your computer and use it in GitHub Desktop.
Save androiddevnotes/065c071c329bbff58b0c2f5b410faae0 to your computer and use it in GitHub Desktop.
# 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