Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Exclusive Mouse Access

Started by Isolier Aug 6, 2005 at 6:52 PM 7 replies 1.1k views
Original Post
Isolier
Isolier
Hello, In my current project I generate terrain from a height map and the user may navigate around this virtual world. I am attempting to implement moving with the keyboard (a, d, w and s keys) and viewing with the mouse as in a first person shooter style move\look scheme. The issue I am having is "losing" the mouse as the user moves the mouse around because as soon as the cursor(which I have set to invisible) moves out of the client area it obviously stops sending mouse move messages to my application. Now I know there is a way to "trap" the mouse input because this is exactly what Jake2 does. When you load the game windowed or not the cursor disappears and mouse movement translates to looking around regardless of the operating systems interpretation of the where the cursor is. Anyhow, I have googled the crap out of this and just can't seem to find any information that pertains to my situation. So, any help would be very much appreciated, thank you in advance.
CaptainJester
CaptainJester
Jake2 might be using LWJGL or other library that provides its own mouse API that gives better control than the standard Java APIs.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
n0rmanfreak
n0rmanfreak
hi!

maybe just set the mouse-position back to the center of your application each time the listener is called...so your cursor is fixed in the center.

hope this helps
Optus
Optus
If you can keep the mouse centered, as per other suggestions. Here's a thread about a good way to hide the cursor: Hiding Mouse Cursor
Isolier
Isolier
I already have the cursor hidden, I just need to find a way to keep the cursor centered. I am beginning to think that a library such as JInput which will allow me to track mouse input at a lower level is the way to go.
n0rmanfreak
n0rmanfreak
hi !

okay, i assumed you are using the MouseMotion Listener. what are you using to detect your mouse motion ?
i think using the MouseMotion Listener to get the movement and setting the mouse back to the center is pretty straight forward.

hope this helps
Isolier
Isolier
Hello,

I am indeed using a MouseMotionListener however I am unaware of a method that sets the cursor where you want it. There is the translate() method but that simply sends a mouse message to the specified point as if the mouse were there, but does not actually move the cursor so the problem would be the same once the user moved the mouse to the edge of the screen. As far as the Robot class you must use signed jars if your going to use it because it has the potential to be used maliciously so I am trying to stay away from Robot. If it comes down to it I will just have to use JInput I suppose.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.