LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Itun on April 05, 2011, 02:22:34

Title: org.lwjgl.input: Get input events timely
Post by: Itun on April 05, 2011, 02:22:34
How I can get events timely?
I mean that how I can use listener for keyboard or mouse.
Because It is inconvenient to get events with query.
I need to have keyboard press timing and I must know a certain time of key press and I don` t need scroll the whole event buffer.

The main problem is that I have camera manager which must have input manager and I have TWL GUI, which also must have its own input manager. When I begin to scroll through the event buffer I get  camera events, but also I get TWL input events.

What will advise? I have no ideas at all.
Title: Re: org.lwjgl.input: Get input events timely
Post by: CodeBunny on April 07, 2011, 14:10:04
If you want "listener" style input, then I would suggest putting an "InputHandler" in your game loop that, every frame, goes through the input for mouse and keyboard and parses every event. Then, give the Handler a list or lists of MouseListener/KeyListener/etc. objects (or custom equivalents) and have the Handler apply the events to the listeners - sort of like how Swing does it.

Assuming your game is keeping a good framerate, the maximum input delay will be just under one frame, and the user won't notice. Also, you can have additional objects add listeners to your input Handler, and your input situation becomes a bit more dynamic.

As to how to tie that into TWL, you'll have to ask someone else. I've never worked with it.