pynput icon indicating copy to clipboard operation
pynput copied to clipboard

mouse.position is not work in fps game( overwatch )

Open m986883511 opened this issue 3 years ago • 2 comments

import pyautogui
import time
from pynput.mouse import Listener, Controller

mouse_controller = Controller()


class LeftButton:
    status = False


def on_click(x, y, button, is_press):
    LeftButton.status = is_press
    print(f"mouse {button} at ({x}, {y}) {'press' if is_press else 'release'}")


mouse_listener = Listener(on_click=on_click)
mouse_listener.start()

try:
    while True:
        x, y = pyautogui.position()
        if LeftButton.status:
            y += 1
            mouse_controller.position = x, y
            # pyautogui.moveTo(x,y, 0.05)
            ppp = "move x:{} y:{}".format(str(x), str(y))
            print(ppp)

        else:
            ppp = "current x:{} y:{}".format(str(x), str(y))
            print(ppp)
        time.sleep(0.01)
except KeyboardInterrupt:
    print('end')

if you press left mouse button, y positon will move downword,but it dont work in overwatch(use 76,fps game)

m986883511 avatar Mar 17 '21 13:03 m986883511

Thank you for your report.

When setting the mouse position, pynput will send an absolute movement using SetCursorPos (I assume that you are using Windows). I suspect that a game would rather react to relative movements.

The pynput.mouse.Controller.move method allows for relative movement in theory, but is implemented as read position + offset + write position on Windows. Perhaps an overload using SendInput would fix this issue.

I do not have time to try this right now, but I might in a couple of days. Would you be able to test the solution in that case?

moses-palmer avatar Mar 29 '21 20:03 moses-palmer

I test it at osu, it has same problem. (just a report)

rexwu1104 avatar Jun 19 '23 01:06 rexwu1104