Python实现软件自动登录&超时锁屏

就这个东西总是掉线 ↓

*如果脚本需要点击 再执行脚本期间不要锁屏   锁屏后点击事件失效

#  用于 V_P_N 退出时  自动点击

# 点击屏幕指定像素点
# 左上角 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

search.png下载

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值