竟然有人用python做這種事 ۦُ۟۟ۖۖۖٛۥۗۙۙۗۡۥٌۚۚۗۛۥۛۚۛۡۥۖۛۛۦُُ۟۟ۖۖۖٛ۟ۗۖۚۥٌُٞۖۛۚ۟ۥٌٌۖۖ۟ۖۦٌ (Python 實現掛機自動鎖屏)


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

發佈了50 篇原創文章 · 獲贊 9 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章