【问题标题】:Roblox won't detect mouse movement from autopyguiRoblox 不会从 pyautogui 检测到鼠标移动
【发布时间】:2022-11-18 14:51:15
【问题描述】:

我正在尝试创建一个脚本,在断开连接时自动重新加入 roblox 游戏。我一直在使用 ctypes 获取屏幕上的一个像素,如果该像素匹配一种颜色,它应该会自动按下重新加入按钮。问题是它不会按下按钮。经过一些故障排除后,我发现鼠标移动不会注册到游戏中,就像我手动移动鼠标一样,它会点击按钮。

简而言之,游戏不会检测来自 pyautogui 的鼠标移动。如果我手动移动鼠标,它会注册。

视频示例: https://youtu.be/VvAfHHXul8Q

代码:

import pyautogui as py
import keyboard
import tkinter
import requests
from ctypes import windll
from time import sleep

key = "m"
toggled = False
rjcolor = 16777215

root = tkinter.Tk()
root.withdraw()

width, height = root.winfo_screenwidth(), root.winfo_screenheight()

dc= windll.user32.GetDC(0)

def getpixel(x,y):
    return windll.gdi32.GetPixel(dc,x,y)

while True:
    if keyboard.is_pressed(key):
        toggled = not toggled
        print("toggled to " + str(toggled))
        sleep(0.5)
    if toggled == True:
        py.moveTo(width / 2, 800)
        py.click(button='left')
        if getpixel(1050, 600) == rjcolor:
            print("disconnected, waiting until internet back online!")
            while True:
                try:
                    requests.head("http://www.google.com/", timeout=3)
                    print('The internet connection is active, rejoining.')
                    py.moveTo(1050, 590)
                    py.mouseDown(button='left')
                    sleep(0.1)
                    py.mouseUp(button='left')
                    break
                    
                except requests.ConnectionError:
                    print("The internet connection is down")
                sleep(3)
    sleep(0.1)

【问题讨论】:

    标签: python roblox pyautogui


    【解决方案1】:

    Pyautogui 在点击 roblox 时出现问题,但我找到了解决方法:

    py.click(button="left")替换为autoit.mouse_click("left")

         import autoit
         autoit.mouse_click("left")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-03
      • 2021-05-23
      • 2019-04-13
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      相关资源
      最近更新 更多