import time
import keyboard
from pynput import mouse
from os import system
from threading import Thread
# 每次保存时间
last =int(time.time())# 保存键盘操作的当前时间defcallback(event):global last
last =int(time.time())# 键盘线程defenter():# 键盘事件
keyboard.hook(callback)
keyboard.wait()# 保存鼠标点击的当前时间defon_click(x, y, button, pressed):ifnot pressed:global last
last =int(time.time())# 点击线程defmc():with mouse.Listener(on_click=on_click)as lister:
lister.join()
lister = mouse.Listener(on_click=on_click)
lister.start()# 监视线程defcheck():whileTrue:
time.sleep(60)# 每个60秒检测一下global last
ifint(time.time())- last >7200:
system('shutdown -s -t 5')if __name__ =='__main__':# 创建 Thread 实例
t1 = Thread(target=enter)
t2 = Thread(target=mc)
t3 = Thread(target=check)# 启动线程运行
t1.start()
t2.start()
t3.start()