Any Key Pressed

Looking at the javadoc I don’t see a way to see if there is a keypress without explicitly checking a keycode. I’m not using buffered mode. What I would like to do is something like…

Keyboard.isKeyDown(KEY_ANYKEY);

is this possible and I’m just missing something. If it isn’t possible any chance it will become possible?

thanks.

uhm

Keyboard.poll();
      if(Keyboard.isKeyDown(Keyboard.KEY_A)) {
    ... //do stuff
}

should do fine?

uhm yourself.

That only returns true if ‘A’ is pressed. I want an option that returns true if any key is pressed, false if no keys are pressed.

Just do:


boolean keyPressed = false;
for (int i = 0; i < 255; i ++) {
if (Keyboard.isKeyDown(i)) {
keyPressed = true;
break;
}
}

That’s all you need to do. Nothing clunky about it at all either. We don’t need to do it in LWJGL, because it’s beyond our remit.

Cas :slight_smile:

ok, that’s what I was doing now, just wanted to see if I could move some code out. :wink:

Thanks.

You could also switch from polling to buffered keyboard input.


Keyboard.create();
Keyboard.enableBuffer();

...

Keyboard.read();
while (Keyboard.next()) {
  if (Keyboard.state) {
    // A key has been pressed    
    // Don't break out of while loop, we need to eat
    // all the keyboard events to empty the buffer.
  }
}


In my current implementation it is better for me to drop some keys over taking the time to check all of them. I originally had it buffered, but a single key press would add too many instances of a keypress. I found that just polling and checking for the key allowed me to drop extraneous key presses without the user noticing.

[quote] uhm yourself.
[/quote]
DOH! - misread your post ::slight_smile: