就這個東西總是掉線 ↓
*如果腳本需要點擊 再執行腳本期間不要鎖屏 鎖屏後點擊事件失效
# 用於 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