# LWJGL - Keyboard.next() not firing

I am trying to make a class which will handle all of my inputs, however Keyboard.next() isn't returning true. Here is my code.

    while(Keyboard.next()) {
if(Keyboard.getEventKey() == Keyboard.KEY_SPACE) {
if (Keyboard.getEventKeyState()) {
System.out.println("Pressed");
}else {
System.out.println("Released");
}
}
}


When I removed the while loop, it infinitely outputs Pressed/Released so I know that part of the code is working. Is there something that I am missing to make this fully work?

This code must be in the update method, if not it won't work. So you cannot seperate it in another class.

The meanings of the single methods, next() and getEventKeyState() are in the lwjgl docs, if you want more information.

while (Keyboard.next()) {
if (Keyboard.getEventKeyState()) {
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
System.out.println("Pressed");
}
}
}

• You should expand this answer with why this works. What's it doing? What problem is it solving? – MichaelHouse May 1 '14 at 21:14
• I edited it. Hope it is good enough and helps. :) – Kronos May 2 '14 at 10:35
• It's wrong and telling them to "go look it up" doesn't make for a good answer. You're not even giving a little bit of information, obviously if they wanted to know more before you said to "go look it up" they would have looked in the docs, so your statement doesn't add much. Further, you can separate the code into another class, making a keyboard object and then populating it in the update method is totally valid. – MichaelHouse May 2 '14 at 14:40
• I figured out the problem in the end. I wasn't calling the function properly. Sorry for not clarifying that. – Brian May 2 '14 at 21:49