[java] Exclusive Mouse Access

Started by
7 comments, last by Isolier 18 years, 8 months ago
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.
Advertisement
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][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
You can hack delta mouse movement with java.awt.Robot-class. You can get source-code too for free from brackeen.com. It's not a pretty solution but I guess it works. Though I'd suggest using LWJGL or JInput to get real delta movement.
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
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
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.
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
Quote:Original post by 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.


So.. did you check out java.awt.Robot? It has a method mouseMove(x,y).
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.

This topic is closed to new replies.

Advertisement