# 基于windows系统 实现思路是检测鼠标坐标超过多久未移动调用系统锁屏
# 加载所需模块
import pyautogui,time
from ctypes import *
# 用于计数
t = 0
# 第一次点击时的坐标
first_x = 0
first_y = 0
# 挂机多久秒后锁屏
time_out = 120
try:
# 一直执行
while True:
# 获取鼠标坐标
this_x, this_y = pyautogui.position() #返回鼠标的坐标
# 判断当前坐标和上次首次是否相同
if (this_x == first_x and this_y == first_y):
# 计数器加1
t += 1
else:
# 计数器清零
t = 0;
# 重新赋值坐标
first_x = this_x
first_y = this_y
if (t > time_out):
print('锁屏')
# 锁屏程序
user32=windll.LoadLibrary('user32.dll')
user32.LockWorkStation()
t = 0
print('running', t)
time.sleep(1)
except KeyboardInterrupt:
print('\nDone.')
此脚本基于windows系统 Python 3.6+