Mr.延禄 2022-07-05 21:14
浏览 96
已结题

python win32api 句柄正确但点击失败

python win32api 句柄正确但点击失败


```python
def mouseClick(clickTimes,lOrR,img,reTry):
    if reTry == 1:
        while True:
            location=pyautogui.locateCenterOnScreen('C:/Users/z1782/Desktop/waterRPA/' + 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("坐标:", location.x, location.y)
                houtaiClick(location.x, location.y, 328290)
                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)
                houtaiClick(location.x, location.y, 328290)        
            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)
                houtaiClick(location.x, location.y, 328290)
                print("重复")
                i += 1
            time.sleep(0.1)

            
def houtaiClick(x, y, hwnd):
    print("x:",x,"y:", y, "hwnd", hwnd)
    long_position = win32api.MAKELONG(x, y)
    print("long_position",long_position)

    time.sleep(0.05)
    back1 = win32api.PostMessage(hwnd,win32con.WM_LBUTTONDOWN,win32con.MK_LBUTTON,long_position)
    time.sleep(0.05)
    back2 = win32api.PostMessage(hwnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON,long_position)

![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/097087620756134.png "#left")
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 7月13日
    • 创建了问题 7月5日

    悬赏问题

    • ¥15 微生物组数据分析--微生物代谢物
    • ¥30 求一跃动小子保卫主公算法实现
    • ¥15 地图软件开发技术答疑(api, 地点获取,外观样式)
    • ¥20 物理远程控制麦克风使用问题
    • ¥15 打印预览会泄漏纸钱包密码吗
    • ¥15 在hololens1上运行unity项目只有空窗口
    • ¥25 TABLEAU PREP无法打开
    • ¥15 百度帐号问题/centos
    • ¥15 关于#c语言#的问题:求完整代码条件好说
    • ¥100 HALCON DELPHI