公司的windows台式机接入了域, 域管理员控制电脑的锁屏时间为9分钟,由于目前我使用的是自己的笔记本, 笔记本通过vnc偶尔连接使到windows台式机,不想让它自动锁屏,于是有如下脚本
功能:
当鼠标键盘没有操作之后8分钟,点击右下角显示桌面(屏幕坐标视具体情况而定), 2秒之后再次点击此处,还原桌面
代码
#coding=utf8
from ctypes import Structure, windll, c_uint, sizeof, byref
import threading
import time
from pymouse import PyMouse
TIMEOUT = 8*60
class LASTINPUTINFO(Structure):
_fields_ = [
('cbSize', c_uint),
('dwTime', c_uint),
]
def move():
m = PyMouse()
x, y = m.position()
m.move(1919,1079)
m.click(1919,1079)
time.sleep(2)
m.click(1919,1079)
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 work():
event = threading.Event()
while not event.wait(20):
s = get_idle_duration()
print('Leave Time: {}s'.format(s))
if s > TIMEOUT:
move()
work()
pyHook下载地址
pyHook下载地址-64位