Hi,
i am using the Keyboard class for handling keyboard input events to turn lights on and off. It currently looks similar to this:
if(Keyboard.isKeyDown(Keyboard.KEY_L)) {
light = !light;
if (light) glEnable(GL_LIGHTING);
else glDisable(GL_LIGHTING);
However, when i hold the L-Key down the light keeps flickering because many KeyDown-Events are generated. What would be the best way to ensure that the light is only toggled once when a user presses a key. A KeyUp-Event would help but there is none in the Keyboard class.
either use a boolean toggle or use the keyboard even mechanism. The latter is probably better.
this is one way, using Keyboard.getEventState();
while (Keyboard.next()) {
int key = Keyboard.getEventKey();
if (Keyboard.getEventKeyState()) { //if key is DOWN
switch (key) {
case Keyboard.KEY_L:
light = !light;
if (light) glEnable(GL_LIGHTING);
else glDisable(GL_LIGHTING);
break;
case Keyboard.KEY_#:
...
break;
}
} else { //if key is is UP
switch (key) {
case Keyboard.KEY_#:
...
break;
case Keyboard.KEY_#:
...
break;
}
}
}
Thank you, it works fine now