Skip to content

Instantly share code, notes, and snippets.

@ArtemBernatskyy
Forked from alexeiz/desktop_activity.py
Created October 13, 2020 13:00
Show Gist options
  • Save ArtemBernatskyy/13d7ac1060b0677eb0d9590650b244dd to your computer and use it in GitHub Desktop.
Save ArtemBernatskyy/13d7ac1060b0677eb0d9590650b244dd 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