Event handling

Hi

I checked Nehe's lesson 7 in LWJGL, and i saw

private void mainloop() {
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { // Exit if Escape is pressed
done = true;
}
if(Display.isCloseRequested()) { // Exit if window is closed
done = true;
}
if (…)



I think this is a bad method for event handling...
what is the best way to handle mouse&key events?
I want my "Idle()" look to run as long as no input event occured... how can i do it?

Thi

Hi

I checked Nehe’s lesson 7 in LWJGL, and i saw the following code:

private void mainloop() {
        if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {       // Exit if Escape is pressed
            done = true;
        }
        if(Display.isCloseRequested()) {                     // Exit if window is closed
            done = true;
        }
       if (...)

I think this is a bad method for event handling…
what is the best way to handle mouse&key events?
I want my “Idle()” look to run as long as no input event occured… how can i do it?

events are handled like this:


while(Keyboard.next())
{

}

while(Mouse.next())
{
   Mouse.getEventX();
   Mouse.getEventY();
   etc etc etc
}

You should look in the javadocs of LWJGL for all event-based methods

But this “while(…)” loops prevent from other things to take place (like animation) as long as the keyboard is constantly pressed, or the mouse…
In JoGL for example, input events can occur simultaniously (by listeners) with drawing, or am i wrong here?

this is a typical way to organize the main thread of a game:
http://svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/src/java/org/lwjgl/examples/Game.java?revision=2286&view=markup

I said: read the javadocs about input-handling in LWJGL…

Keyboard.next() and Mouse.next() are non-blocking

Thanks for both if you very much, I’ll try both methods :slight_smile: