游戏无法理解由 win32api 或 pyautogui 完成的鼠标移动

问题描述 投票:0回答:1

我想做一个简单的程序,在屏幕上查找“skip_button.png”,如果找到,将鼠标移动到其坐标并按 LMB,一切正常,但鼠标按下。问题是按钮是不可点击的,除非游戏认为你将鼠标移到了它上面,当鼠标移动时,它会变得稍微大一点并且可点击,如果我只是物理地移动鼠标,它显然可以工作,但是如果鼠标是由 pyautogui 移动的/autopy/win32api 游戏不会执行任何操作,需要我移动身体才能按下按钮。顺便说一句,它是 roblox。

有什么解决办法吗?

import pyautogui as ag
import win32api, win32con
from time import sleep
import keyboard as kb
print(kb._os_keyboard.from_name)

def move(x, y):
    win32api.SetCursorPos((x,y))
def click():
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0,0)
    sleep(0.10)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0,0)
while True:
    sleep(1)
    res = ag.locateCenterOnScreen("C:/Users/YM/Desktop/python_vscode/tds_autoskip/skip_button.png", confidence=0.8)
    if res != None:
        x, y = res
        print(x,y)
        
        move(x,y)
        sleep(0.5)
        click()

    else:
        print("no find")

这是我的代码

python pyautogui
1个回答
0
投票

好吧,您的问题有一个解决方案,那就是稍微移动鼠标:

import pyautogui as ag
import win32api, win32con
from time import sleep
import keyboard as kb
import random
print(kb._os_keyboard.from_name)

def move(x, y):
    win32api.SetCursorPos((x,y))
def click():
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0,0)
    sleep(0.10)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0,0)
while True:
    sleep(1)
    res = ag.locateCenterOnScreen("C:/Users/YM/Desktop/python_vscode/tds_autoskip/skip_button.png", confidence=0.8)
    if res != None:
        x, y = res
        print(x, y)
        
        move(x, y)
        sleep(0.5)
        # Simulate a small mouse movement
        move(x + random.randint(-1, 1), y + random.randint(-1, 1))
        sleep(0.1)
        click()

    else:
        print("no find")
© www.soinside.com 2019 - 2024. All rights reserved.