需求:
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()
if __name__ == "__main__":