pynput
pynput copied to clipboard
mouse.position is not work in fps game( overwatch )
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)
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?
I test it at osu, it has same problem. (just a report)