需求:
1.检测2分钟没有移动鼠标,锁定计算机。
2.检测45分钟自动锁定计算机,提醒用户休息,久坐有害健康。
import ctypes;
import threading;
import time;
import os;
import pyautogui as pag
def shotdown():
dll = ctypes.WinDLL('user32.dll');
dll.LockWorkStation();
cnt =0
gg = 0
def hello():
x, y = pag.position() # 返回鼠标的坐标
# posStr = "Position:" + str(x).rjust(4) + ',' + str(y).rjust(4)
# print(posStr)
global gg
if(gg == x):
shotdown()
else:
gg = x
global timer
global cnt
cnt = cnt+1
if (cnt==45):
cnt = 0
shotdown()
timer = threading.Timer(60.0, hello)
timer.start(

这篇博客介绍了一个Python脚本,该脚本能够检测鼠标无移动2分钟后自动锁定计算机,或每45分钟锁定一次以提醒用户休息。通过pyautogui库获取鼠标位置,并使用pywin32和pyinstaller将脚本打包成exe文件,同时说明了如何将exe添加到系统启动项以实现开机自启动。


被折叠的 条评论
为什么被折叠?



