Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Mouse Moves in Wrong Direction When Turning GrabMouse On #810

Open
Hades948 opened this issue Feb 24, 2024 · 1 comment
Open

Mouse Moves in Wrong Direction When Turning GrabMouse On #810

Hades948 opened this issue Feb 24, 2024 · 1 comment
Labels

Comments

@Hades948
Copy link
Contributor

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.

@Hades948 Hades948 added the bug label Feb 24, 2024
@nightm4re94
Copy link
Member

Thanks for the elaborate example! Will check this out when I'm back from vacation in March.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants