Skip to content

Mouse Moves in Wrong Direction When Turning GrabMouse On #810

@Hades948

Description

@Hades948

Describe the bug
When I call Input.mouse().setGrabMouse(true), the mouse moves in the wrong direction.

I want the player to be able to turn grab mouse on and off, so they can get out of the window without completely closing the game. When I turn grab mouse off, I figure out where the game mouse is and I use a robot to move the actual mouse to that location after calling setGrabMouse(false). This works fine. But when I turn grab mouse on, I'd expect the game mouse to stay where it is (or at the very least, return to the center of the screen). But, instead, it seems to be moving the distance between it and the center of the window, but in the wrong direction.

I believe this is happening in Mouse.setLocation(MouseEvent):
image

This is, of course, the correct behavior when grab mouse is on. But I think it's incorrect when grab mouse was off during the last update, but is now on. Again, in that case, I think I'd expect the game mouse's position to just stay where it is (even if the mouse is moving back to the center of the screen).

Here's a GIF where I try to demo it, but it's a little hard to show. Details on how to reproduce are below.
java_4ZbXZ7ULbt

To Reproduce
Steps to reproduce the behavior:

  1. Throw this code in your main() or somewhere:
    image
    VirtualMouse.instance().getLocationOnScreen() does the following:
    image
    Utils.robot is just a normal Robot object.

  2. Run the game and press Alt to release the mouse.

  3. Click somewhere on the screen. Closer to the middle is easier to see what's happening. The game mouse will jump away from the center of the screen.

Your System:

  • OS: [e.g. iOS]
  • LITIENGINE version: 0.6.1
  • Java JDK/JRE version: jdk-21.0.1
  • Screen resolution: 4K

Btw, I welcome feedback on this code. I haven't worked with the mouse and robots much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions