Using LWJGL's version of JInput

Started by laginimaineb, October 04, 2007, 10:29:37

Previous topic - Next topic

laginimaineb

Hello, I'm working on a 2D Jump'n Run game using Java2D. Since I need fast good Keyboard interaction I can't rely on the KeyEvents, so I tried JInput, however, I seem to be running into many problems while developing on Linux. Now, since I already used LWJGL and remembered it uses JInput as well, and works on my Linux box, I wondered whether it is possible to use the org.lwjgl.input.Keyboard without actually using a LWJGL display... When I try this I get an Exception saying "The Display must be Created" or something of the sort.

Lots of thanks,
laginimaineb.

Orangy Tang

Regular KeyboardListener code will work fine for a fast jump and run game (I know, I've done it). You just have to keep track of keyboard state yourself instead of relying on keyboard repeat events. Keep an array/map of bools for all the keys you're interested in, then set them on keyPressed and unset them on keyReleased events. Your main game loop thread just has to query this array and act on it. Simple, fast and effective.

laginimaineb

Hey, thanks for your quick response. Thing is, the game is really massive and needs to reach lots of FPS, meaning all AWT events take about 1-2 seconds to really trigger my listeners. Instead of AWT I want to poll the keyboard data. I know LWJGL does this using the JInput library, which I am also currently trying to use... It's just that on Linux JInput gives me lots of problems such as detecting 3 keyboards when only one is present... Anyway, I think I'll just try to get a better grip on JInput. Thanks for all your help anyway.

Orangy Tang

Quote from: laginimaineb on October 04, 2007, 16:53:00
Hey, thanks for your quick response. Thing is, the game is really massive and needs to reach lots of FPS, meaning all AWT events take about 1-2 seconds to really trigger my listeners.
Then either you're doing something wrong or the Linux VM is horribly broken. If you've got a single keyboard listener and pay attention to keyPressed and keyReleased (*not* keyTyped, since the auto-repeat is inappropriate and slow) then you get key state near instantaneously. I've run games at 75fps with this approach and and theres no delay at all on the keyboard input.

I wonder if you've messed with the thread priorities and are starving the AWT event queue.