├── requirements.txt ├── README.md └── app.py /requirements.txt: -------------------------------------------------------------------------------- 1 | PyAutoGUI==0.9.52 2 | idle_time==0.1.0 3 | progressbar33==2.4 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This script makes sure your PC isn't automatically locked when left unattended 2 | 3 | Install the dependencies by running 4 | ``` 5 | pip install -r requirements.txt 6 | ``` 7 | 8 | To run the application run 9 | ```python app.py``` or ```python3 app.py``` 10 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Install the dependencies using 3 | pip install -r requirements.txt 4 | 5 | or install it manually 6 | pip install idle-time 7 | pip install pyautogui 8 | pip install progressbar 9 | ''' 10 | 11 | from idle_time import IdleMonitor 12 | from datetime import datetime 13 | import time 14 | import pyautogui 15 | import progressbar 16 | from ctypes import Structure, windll, c_uint, sizeof, byref 17 | 18 | ALLOWED_IDLE_TIME = 180 #In seconds 19 | 20 | counter = 1 21 | startTime = datetime.now().timestamp() 22 | 23 | 24 | def main(): 25 | print(f"Starting with idle time out as {ALLOWED_IDLE_TIME} seconds") 26 | while True: 27 | forever() 28 | 29 | 30 | class LASTINPUTINFO(Structure): 31 | _fields_ = [ 32 | ('cbSize', c_uint), 33 | ('dwTime', c_uint), 34 | ] 35 | 36 | 37 | def get_idle_duration(): 38 | lastInputInfo = LASTINPUTINFO() 39 | lastInputInfo.cbSize = sizeof(lastInputInfo) 40 | windll.user32.GetLastInputInfo(byref(lastInputInfo)) 41 | millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime 42 | return millis / 1000.0 43 | 44 | def forever(): 45 | #monitor = IdleMonitor.get_monitor() 46 | #prevTime = monitor.get_idle_time(); 47 | prevTime = get_idle_duration(); 48 | bar = progressbar.ProgressBar(maxval=ALLOWED_IDLE_TIME, widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()]) 49 | bar.start() 50 | while True: 51 | time.sleep(1) 52 | #idleTime = monitor.get_idle_time() 53 | idleTime = get_idle_duration() 54 | if prevTime > idleTime: 55 | bar.start() 56 | prevTime = idleTime 57 | bar.update(min(idleTime + 1, ALLOWED_IDLE_TIME)) 58 | if(idleTime > ALLOWED_IDLE_TIME): 59 | pyautogui.press('win') 60 | time.sleep(0.15) #necessary else two keypresses sometimes getting registered as one 61 | pyautogui.press('win') 62 | bar.finish() 63 | global counter 64 | timeWorked = (datetime.now().timestamp() - startTime - (counter * ALLOWED_IDLE_TIME))/60 65 | afkTime = counter * ALLOWED_IDLE_TIME / 60 66 | 67 | print(f"You were afk for {format(afkTime, '.3f')} minutes, and you have worked for {format(timeWorked, '.3f')} minutes or {format(timeWorked/60, '.3f')} hours") 68 | counter += 1 69 | return 70 | 71 | if __name__ == "__main__": 72 | main() --------------------------------------------------------------------------------