-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (34 loc) · 1.02 KB
/
Copy pathmain.py
File metadata and controls
42 lines (34 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import psutil
import time
from datetime import datetime
import keyboard
import mouse
LOG_FILE = "vscode_time_log.txt"
PROCESS_NAME = "Code.exe" # Process name for VS Code on Windows
AFK = False # Flag to check if the user is AFK
def log_time():
# Log the current time if active and not AFK
with open(LOG_FILE, "a") as f:
f.write(f"{datetime.now()}\n")
def is_vscode_running():
# Check if VS Code is running
for process in psutil.process_iter(['name']):
if process.info['name'] == PROCESS_NAME:
return True
return False
def reset_afk_flag(_):
global AFK
AFK = False # Set the flag if there's any input
def main():
global AFK
# Attach handlers for keyboard and mouse
keyboard.hook(reset_afk_flag)
mouse.hook(reset_afk_flag)
while True:
if is_vscode_running() and not AFK:
log_time()
# Reset AFK flag for the next interval
AFK = True
time.sleep(60) # Wait for 1 minute (60 seconds)
if __name__ == "__main__":
main()