简体   繁体   English

无法在 Roblox 上移动鼠标

[英]can't move mouse on Roblox

I tried out two different libraries for this but ran into the same issue.我为此尝试了两个不同的库,但遇到了同样的问题。

pyautogui.moveTo(100,100)
pydirectinput.moveTo(100,100)

The code works fine outside of Roblox but whenever I run it with Roblox as the active window I have to slightly move my mouse for python to move to the location I want该代码在 Roblox 之外运行良好,但是每当我使用 Roblox 作为活动窗口运行它时,我都必须稍微移动鼠标让 python 移动到我想要的位置

I will not question your motives...我不会质疑你的动机......

import ctypes
from ctypes.wintypes import DWORD, WORD
from math import floor
emptyLong = ctypes.c_ulong()

class MouseInput(ctypes.Structure):
    _fields_ = [("dx", ctypes.c_long),
                ("dy", ctypes.c_long),
                ("mouseData", DWORD),
                ("dwFlags", DWORD),
                ("time", DWORD),
                ("dwExtraInfo", ctypes.POINTER(ctypes.c_ulong))]

class KeybdInput(ctypes.Structure):
    _fields_ = [("wVk", WORD),
                ("wScan", WORD),
                ("dwFlags", DWORD),
                ("time", DWORD),
                ("dwExtraInfo", ctypes.POINTER(ctypes.c_ulong))]

class HardwareInput(ctypes.Structure):
    _fields_ = [("uMsg", DWORD),
                ("wParamL", WORD),
                ("wParamH", WORD)]

class InputList(ctypes.Union):
    _fields_ = [
        ("mi", MouseInput),
        ("ki", KeybdInput),
        ("hi", HardwareInput)]

class Input(ctypes.Structure):
    _fields_ = [("type", ctypes.c_ulong),
                ("inputList", InputList)]

MOUSEEVENTF_MOVE = 0x0001
MOUSEEVENTF_ABSOLUTE = 0x8000
def move(x, y, relative=False): # MOVE MOUSE TO (X, Y)
    mouseFlag = MOUSEEVENTF_MOVE

    if not relative:
        mouseFlag |= MOUSEEVENTF_ABSOLUTE
        x = floor(x/1920 * 65535) # ASSUMING COORDINATES ARE BASED ON 1920 x 1080 RESOLUTION
        y = floor(y/1080 * 65535)
        
    inputList = InputList()
    inputList.mi = MouseInput(x, y, 0, mouseFlag, 0, ctypes.pointer(emptyLong))

    windowsInput = Input(emptyLong, inputList)
    ctypes.windll.user32.SendInput(1, ctypes.pointer(windowsInput), ctypes.sizeof(windowsInput))

just a little bit of C. Learn more只是一点点 C. 了解更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM