简体   繁体   中英

Move mouse in fullscreen game with Python

I am trying to move my mouse in a fullscreen game (Roblox) using Python, but the mouse jumps to a set position only if I move my mouse manually.

My code is:

from pydirectinput import Input, Input_I, MouseInput
def MoveMouse(x, y):
    extra = ctypes.c_ulong(0)
    ii_ = Input_I()
    x = int(x*(65536/ctypes.windll.user32.GetSystemMetrics(0))+1)
    y = int(y*(65536/ctypes.windll.user32.GetSystemMetrics(1))+1)
    ii_.mi = MouseInput(x, y, 0, 0x0001 | 0x8000, 0, ctypes.pointer(extra)) 
    x = Input(ctypes.c_ulong(0), ii_)
    ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
MoveMouse(50,50)

I tried using many other modules (mouse, pynput, pydirectinput), but they do the same problem.

Try to use pyautogui. It has moveTo() function I guess it will be work.

https://pyautogui.readthedocs.io/en/latest/

I use it for work with microsoft office eg. word excel It work for me and for interface on website but never use with the game system not sure for it. try.!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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