Skip to content

Instantly share code, notes, and snippets.

@TylerCode
Last active August 12, 2023 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TylerCode/b3e6c244aae8f31dbf02ba00221a3641 to your computer and use it in GitHub Desktop.
Save TylerCode/b3e6c244aae8f31dbf02ba00221a3641 to your computer and use it in GitHub Desktop.
Run this with BG to save every 10 min
import psutil
import time
from pynput.keyboard import Key, Controller
time.sleep(10)
def check_if_process_running(process_keywords):
try:
# Check every process cause this wasn't working.... idk why
for proc in psutil.process_iter():
try:
# Check if process name contains any of the keywords.
if any(keyword.lower() in proc.name().lower() for keyword in process_keywords):
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
except Exception as e:
print(e)
return False
process_keywords = ["bg3", "baldur"]
keyboard = Controller()
while True:
if check_if_process_running(process_keywords):
# Press and release F5 to fucking save because GD Dave didn't think autosave was important
keyboard.press(Key.f5)
keyboard.release(Key.f5)
print(f"A process with keywords {process_keywords} is running, pressed F5.")
else:
print(f"No process with keywords {process_keywords} is running.")
time.sleep(600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment