From 7086b0c37b9058fb305c0b387909df0ad0435e58 Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Tue, 3 Oct 2023 10:58:30 -0400 Subject: [PATCH] =?UTF-8?q?if=20computer=20is=20idle=20for=204+=20mins,=20?= =?UTF-8?q?un-idle=20it=20=E2=8C=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ python/gui.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 .gitignore create mode 100644 python/gui.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d22cc8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode* + diff --git a/python/gui.py b/python/gui.py new file mode 100644 index 0000000..ece64ee --- /dev/null +++ b/python/gui.py @@ -0,0 +1,47 @@ +from warnings import catch_warnings +import pyautogui +import time as tim +from datetime import datetime, time +from ctypes import * + +pyautogui.FAILSAFE = False + + +class LASTINPUTINFO(Structure): + _fields_ = [ + ('cbSize', c_uint), + ('dwTime', c_int) + ] + + +def get_duration(): + lastInputlnfo = LASTINPUTINFO() + lastInputlnfo.cbSize = sizeof(lastInputlnfo) + + if windll.user32.GetLastInputInfo(byref(lastInputlnfo)): + millis = windll.kernel32.GetTickCount() - lastInputlnfo.dwTime + return millis / 1000.0 + else: + return 0 + + +while True: + now = datetime.now().time() + fourPm = time(16, 00) + + if now >= fourPm: + print("0") + break + + dur = get_duration() + try: + if (dur > 4 * 60): # 4 mins + print(f"duration = {dur}") + pyautogui.press("shift") + pyautogui.press("f15") + except Exception as e: + print(f"Error encountered {e}") + + tim.sleep(5) # 5 seconds + + # print(f"{now} loop)