以下是一个简单的Python挂机锁代码,它会在计算机空闲一段时间后锁定屏幕。你可以根据需要进行修改和定制。

import time
import ctypes

# 设定空闲时间(秒)
IDLE_TIME = 300

# 获取空闲时间
def get_idle_time():
    return (ctypes.windll.user32.GetTickCount() - ctypes.windll.user32.GetLastInputInfo()) / 1000

# 锁定屏幕
def lock_screen():
    ctypes.windll.user32.LockWorkStation()

# 主程序
if __name__ == '__main__':
    while True:
        idle_time = get_idle_time()
        if idle_time > IDLE_TIME:
            lock_screen()
        time.sleep(60)

这个代码使用了Windows API函数来获取计算机的空闲时间,并且在空闲时间超过设定值时锁定屏幕。你可以将'IDLE_TIME'变量设定为你需要的时间,单位为秒。在主程序中,代码会每隔60秒检查一次空闲时间,以避免过多占用计算机资源。

Python挂机锁代码:自动锁定屏幕

原文地址: http://www.cveoy.top/t/topic/jC1W 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录