Matt
Matt

Reputation: 11357

Keep mouse pointer within frame/window

I want to prevent the mouse from being moved out of the window. I've seen it done before on Minecraft, where you have to press esc to release the mouse from the window.

Upvotes: 2

Views: 3569

Answers (1)

Collin Price
Collin Price

Reputation: 5860

In Java you can use the Class Robot to position the mouse cursor anywhere on the screen. You could use this to move the mouse position back to the center after each mouse move event.

//Moves mouse pointer to given screen coordinates.
void mouseMove(int x, int y)

Upvotes: 6

Related Questions