#!/usr/bin/env python3 # # This simple scenario moves the mouse cursor every N seconds, # keeping the input devices active and preventing the computer # from going into sleep/standby mode. # # Requirements: # # python: # - pyautogui # # MacOS: # - add iTerm to Settings -> Security & Privacy -> Accessibility. # import pyautogui import random import time import sys def timestamp(): return time.strftime("%Y-%H-%M %T", time.localtime(int(time.time()))) t = 1 if len(sys.argv) == 1 else int(sys.argv[1]) screenWidth, screenHeight = pyautogui.size() print(f"[{timestamp()}] Rat-race scenario is started.") print(f"[{timestamp()}] The mouse cursor will move every {t} seconds.") print(f"[{timestamp()}] Current screen resolution is {screenWidth}x{screenHeight}.") try: while True: x, y = random.randrange(screenWidth), random.randrange(screenHeight) print(f"[{timestamp()}] > moving the cursor to point {x : >4},{y}") pyautogui.moveTo(x, y) time.sleep(t) except KeyboardInterrupt: print(f"[{timestamp()}] Interrupted. Exit.") sys.exit(0)