You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
978 B
42 lines
978 B
4 years ago
|
#!/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}.")
|
||
|
|
||
|
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)
|
||
|
|