Python pyautogui 自动控制 MDK Keil_v5 Pack Installer 的 Packs 安装过程

MDK Keil_v5 安装完成后,会自动进行 Pack Installer 的 Packs 安装,安装过程中首先 install 需要一行行用鼠标点,然后每一行的 Pack 都会出现同意安装或连接超时的弹窗,需要鼠标操作确认。

pyautogui 可以帮助自动控制鼠标完成确认,install 这一块是手动点完的,代码里无体现,可使用 pyautogui.locateOnScreen() 通过图标获取位置。

基本思路是,循环获取屏幕截图,通过弹窗的 pixel RGB 值实现弹窗分类,然后进行相应操作,代码使用的位置及 RGB 数据是在 1920*1080 分辨率下采集的。pyautogui.locateOnScreen() 能帮助实现特定操作,用于图像固定、位置变化的场景,如点赞按钮,可参考以下链接。

python 在屏幕上点击特定按钮或图像_python_zzfengling-华为云开发者空间
https://huaweicloud.csdn.net/63806a8ddacf622b8df87612.html

import time
import pyautogui
import PIL
from PIL import Image

# cmd管理员方式运行

def click_install():
    pyautogui.moveTo(721, 622, duration=1)
    pyautogui.click()

    pyautogui.moveTo(1103, 675)
    pyautogui.click()

def click_yesno():
    pyautogui.moveTo(1127, 605)
    pyautogui.click()

def check_pack():
    ret = 0
    img = pyautogui.screenshot()
    if (img.getpixel((1192, 511)) == (205, 205, 205))\
    and (img.getpixel((930, 467)) == (240, 240, 240))\
    and (img.getpixel((977, 639)) == (240, 240, 240))\
    and (img.getpixel((687, 406)) == (240, 240, 240))\
    and (img.getpixel((770, 395)) == (255, 255, 255))\
    and (img.getpixel((721, 622)) == (255, 255, 255)):
        ret = 1
    elif (img.getpixel((1189, 625)) == (240, 240, 240))\
    and (img.getpixel((729, 620)) == (240, 240, 240))\
    and (img.getpixel((912, 607)) == (240, 240, 240))\
    and (img.getpixel((857, 591)) == (240, 240, 240))\
    and (img.getpixel((1177, 564)) == (255, 255, 255))\
    and (img.getpixel((729, 502)) == (255, 255, 255))\
    and (img.getpixel((768, 575)) == (255, 255, 255))\
    and (img.getpixel((1142, 412)) == (255, 255, 255)):
        ret = 2

    return ret

while True:
    time.sleep(5)
    ret = check_pack()
    if (ret == 1):
        click_install()
        print("click_install %s\r\n" %(time.strftime("%Y-%m-%d %H:%M:%S")))
    elif (ret == 2):
        click_yesno()
        print("click_yesno %s\r\n" %(time.strftime("%Y-%m-%d %H:%M:%S")))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值