Skip to content

Instantly share code, notes, and snippets.

@wbhinton
Created December 3, 2019 13:35
Show Gist options
  • Save wbhinton/79c184ae72484c99b462516d18d484ba to your computer and use it in GitHub Desktop.
Save wbhinton/79c184ae72484c99b462516d18d484ba to your computer and use it in GitHub Desktop.
Python Script to keep your screen alive
import pyautogui
import time
import sys
from datetime import datetime
pyautogui.FAILSAFE = False
numMin = None
print('We will keep you computer awake by moving the mouse every 3 minutes. ¯\_(ツ)_/¯')
if ((len(sys.argv)<2) or sys.argv[1].isalpha() or int(sys.argv[1])<1):
numMin = 3
else:
numMin = int(sys.argv[1])
while(True):
x=0
while(x<numMin):
time.sleep(60)
x+=1
for i in range(2):
pyautogui.moveRel(1, 0, duration=0.1)
pyautogui.moveRel(-1, 0, duration=0.1)
for i in range(0,2):
pyautogui.press("shift")
print("Movement made at {}".format(datetime.now().time()))
@Floepke
Copy link

Floepke commented Apr 5, 2021

I found a different solution:

import pyautogui
import time
def function():
while True:
pyautogui.press("ctrl")
print('Pressed ctrl to keep the screen alive')
time.sleep(240)
function()

You only need to press a key every x seconds :) Moving the mouse will be anoying when watching a movie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment