-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshutdown.py
More file actions
38 lines (27 loc) · 997 Bytes
/
Copy pathshutdown.py
File metadata and controls
38 lines (27 loc) · 997 Bytes
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
import evdev
import time
import select
import os
keyboard_device = '/dev/input/event4' # путь к клавиатуре
mouse_device = '/dev/input/event7' # путь к мыши
idle_time = 7200 # время ожидания в секундах до выключения
last_activity_time = time.time()
def check_idle():
return time.time() - last_activity_time > idle_time
def shutdown():
print("No activity detected. Shutting down...")
os.system("shutdown now") # или poweroff
keyboard = evdev.InputDevice(keyboard_device)
mouse = evdev.InputDevice(mouse_device)
# НЕ ЗАХВАТЫВАЕМ УСТРОЙСТВА
# keyboard.grab()
# mouse.grab()
while True:
r, _, _ = select.select([keyboard, mouse], [], [], 1)
for device in r:
for event in device.read():
last_activity_time = time.time() # сброс таймера при активности
if check_idle():
shutdown()
break
time.sleep(1)