就这个东西总是掉线 ↓
*如果脚本需要点击 再执行脚本期间不要锁屏 锁屏后点击事件失效
# 用于 vpn 退出时 自动点击
# 点击屏幕指定像素点
# 左上角 x 837 y 604
# 右下角 x 1101 y 637
import pyautogui, time, sys
from ctypes import *
# 换成具体图片
searchFile = './img/search.png'
i = 0
# 用于计数
t = 0
# 第一次点击时的座标
first_x = 0
first_y = 0
# 挂机多久秒后锁屏
time_out = 120
time_out = time_out/5
def click_screen(i, t, first_x, first_y, time_out):
try:
while True:
time.sleep(5)
i = i+1
try:
#在当前屏幕中查找指定图片(图片需要由系统截图功能截取的图)
coords = pyautogui.locateOnScreen(searchFile)
x,y=pyautogui.center(coords)
y = y - 75
pyautogui.click(x,y)
print('click')
i = 0
except Exception as e:
print('execute: ', i)
# 获取鼠标座标
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):
pyautogui.click(777,0)
print('You have been offline')
# 锁屏程序
# user32=windll.LoadLibrary('user32.dll')
# user32.LockWorkStation()
t = 0
except Exception as e:
print(e, ' this is a error')
time.sleep(120)
click_screen(0, 0, 0, 0, time_out)
click_screen(i, t, first_x, first_y, time_out)
# i = 0
# try:
# while i<86400:
# time.sleep(5)
# pyautogui.click(837, 604)
# i = i+1
# print('执行: ', i, ' 次' )
# except KeyboardInterrupt:
# sys.exit(0)
也可以用于超时锁屏
search.png