# 基於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+