[Python]图形匹配

class GUITest:

    # 定义鼠标事件
    # pyautogui库其他用法 https://blog.csdn.net/qingfengxd1/article/details/108270159
    def mouseClick(self, clickTimes, LOrR, img, reTry):
        if reTry == 1:
            while True:
                location=pyautogui.locateCenterOnScreen(img, confidence=0.9)
                # confidence:相似度
                if location is not None:
                    pyautogui.click(location.x, location.y, clicks=clickTimes, interval=0.2, duration=0.2, button=LOrR)
                    break
                print("未找到匹配图片,0.1秒后重试")
                time.sleep(0.1)
        elif reTry == -1:
            while True:
                location=pyautogui.locateCenterOnScreen(img, confidence=0.9)
                if location is not None:
                    pyautogui.click(location.x, location.y, clicks=clickTimes, interval=0.2, duration=0.2, button=LOrR)
                time.sleep(0.1)
        elif reTry > 1:
            i = 1
            while i < reTry + 1:
                location=pyautogui.locateCenterOnScreen(img,confidence=0.9)
                if location is not None:
                    pyautogui.click(location.x, location.y, clicks=clickTimes, interval=0.2, duration=0.2, button=LOrR)
                    print("重复")
                    i += 1
                time.sleep(0.1)

    #任务
    def mainWork(self,obj,img,sheet1,i):
        #i = 1
        #while i < sheet1.nrows:
        if i < sheet1.nrows:
            #取本行指令的操作类型
            cmdType = sheet1.row(i)[1]
            if cmdType.value == 1.0:
                #取图片名称
                img = sheet1.row(i)[0].value
                reTry = 1
                if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
                    reTry = sheet1.row(i)[2].value
                obj.mouseClick(1,"left",img,reTry)
                print("单击左键",img)
            # 2 代表双击左键
            elif cmdType.value == 2.0:
                #取图片名称
                img = sheet1.row(i)[0].value
                #取重试次数
                reTry = 1
                if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
                    reTry = sheet1.row(i)[2].value
                obj.mouseClick(2,"left",img,reTry)
                print("双击左键",img)
            #3代表右键
            elif cmdType.value == 3.0:
                #取图片名称
                img = sheet1.row(i)[0].value
                #取重试次数
                reTry = 1
                if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
                    reTry = sheet1.row(i)[2].value
                obj.mouseClick(1,"right",img,reTry)
                print("右键",img)
            #4代表输入
            elif cmdType.value == 4.0:
                inputValue = sheet1.row(i)[0].value
                pyperclip.copy(inputValue)
                pyautogui.hotkey('ctrl','v')
                time.sleep(0.5)
                print("输入:",inputValue)
            #5代表等待
            elif cmdType.value == 5.0:
                #取图片名称
                waitTime = sheet1.row(i)[0].value
                time.sleep(waitTime)
                print("等待",waitTime,"秒")
            #6代表滚轮
            elif cmdType.value == 6.0:
                #取图片名称
                scroll = sheet1.row(i)[0].value
                pyautogui.scroll(int(scroll))
                print("滚轮滑动",int(scroll),"距离")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值