域控云桌面 每隔10分钟不敲鼠标键盘必锁屏。每天疲于输入密码,不胜其烦。
假期怒学python ,实现检查系统一段时间没有敲鼠标键盘,则自动按2下num键,阻止防止系统锁屏。
为啥是num键? 因为实在找不到啥别的人畜无害的按键了。哪怕是ScrollLock也是有可能捣乱的。
打包成win7 64位 exe 下载地址:
源码奉上,可自行打包
不要在意代码风格路子野
-
#打包exe命令:pyinstaller -i .\tool.ico -F test.py
-
-
import py_compile
-
from ctypes import *
-
from ctypes import Structure, windll, c_uint, sizeof, byref
-
import time
-
import os
-
import win32api
-
import win32con
-
import configparser
-
-
class LASTINPUTINFO(Structure):
-
_fields_ = [('cbSize', c_uint), ('dwTime',c_uint)]
-
#python调用GetLastInputInfo
-
def get_idle_duration():
-
lastInputInfo = LASTINPUTINFO()
-
lastInputInfo.cbSize = sizeof(lastInputInfo)
-
windll.user32.GetLastInputInfo(byref(lastInputInfo))
-
millis = windll.kernel32.GetTickCount()- lastInputInfo.dwTime
-
return millis / 1000.0
-
-
-
def get_mouse_point():
-
po = POINT()
-
windll.user32.GetCursorPos(byref(po))
-
return po
-
-
class POINT(Structure):
-
_fields_ = [("x", c_ulong),("y", c_ulong)]
-
-
filename = 'tool.ini'
-
mydelay=60*10-20
-
conf = configparser.ConfigParser()
-
print("锁屏汪 V1.00 版 for win7-x64")
-
print("防止10分钟锁屏")
-
#通过配置文件的方式配置mydelay 弃用
-
# if os.path.exists(filename):
-
# conf.read(filename)
-
# if conf.has_option("config", "delay"):
-
# mydelay=conf.get("config", "delay")
-
# else:
-
# conf.add_section('config') # 添加section
-
# conf.set('config', 'delay', str(mydelay)) # 添加值
-
# fp = open(filename, "w")
-
# conf.write(fp)
-
# print(fp.name)
-
# fp.close()
-
print("系统无键鼠输入"+str(mydelay),"秒后,将自动模拟按下2次num按键")
-
while True:
-
#移动鼠标的方式不顶用 还是会锁屏
-
# curpo = get_mouse_point()
-
# print("x =",int(curpo.x), "y =",int(curpo.y))
-
# if i==0:
-
# windll.user32.SetCursorPos(int(curpo.x), int(curpo.y) + 1)
-
# i=1
-
# else:
-
# windll.user32.SetCursorPos(int(curpo.x), int(curpo.y) - 1)
-
# i=0
-
-
# print(get_idle_duration())
-
if get_idle_duration() >= int(mydelay):
-
print(get_idle_duration())
-
win32api.keybd_event(144, 0, 0, 0) # num键位码是144
-
win32api.keybd_event(144, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放按键
-
time.sleep(0.1)
-
win32api.keybd_event(144, 0, 0, 0) # num键位码是144
-
win32api.keybd_event(144, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放按键
-
time.sleep(10)#每隔10s检查一次
-
-
阅读(721) | 评论(1) | 转发(0) |