Skip to content

Instantly share code, notes, and snippets.

@alexeiz
Created April 13, 2018 02:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexeiz/fb8ec7b92cc38bbfe2a03004d0d4b59e to your computer and use it in GitHub Desktop.
Save alexeiz/fb8ec7b92cc38bbfe2a03004d0d4b59e to your computer and use it in GitHub Desktop.
Simulate desktop activity
#!/usr/bin/env python
import sys
import pyautogui
from datetime import datetime, timedelta
def move_rel(dx, dy, dur):
pyautogui.moveRel(dx, dy, dur, pyautogui.easeInQuad)
def square(side, dur):
move_rel(side, 0, dur)
move_rel(0, side, dur)
move_rel(-side, 0, dur)
move_rel(0, -side, dur)
def cycle_win():
pyautogui.keyDown('alt')
pyautogui.keyDown('shift')
pyautogui.keyDown('tab')
pyautogui.keyUp('tab')
pyautogui.keyUp('shift')
pyautogui.keyUp('alt')
def activity():
square(600, 1)
for _ in range(5):
cycle_win()
def main():
dur_min = 1
if len(sys.argv) >= 2:
dur_min = int(sys.argv[1])
until = datetime.now() + timedelta(minutes=dur_min)
while datetime.now() < until:
activity()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment