[SOLVED] Keyboard.next() not working

I recently started working on my first JME game. I couldn’t find a 2d lib that really fit my project needs so I wrote one and its working great, but I’ve had some major issues getting my chatbox input to work… when I use JME’s keyboard code it would spam my chatbox with the same character unless I quickly tapped the key, so I wrote my own generic lwjgl keyboard listener:

public void simpleUpdate(float tpf) {
     * Handle keyboard input
    while (Keyboard.next()) {
        //for (int i = 0; i < keysDown.length; i++) {
        //    keysDown[i] = Keyboard.isKeyDown(i);
       // }
        client.pollKeyboardInput(Keyboard.getEventKey(), Keyboard.getEventCharacter(), Keyboard.getEventKeyState());

And this is the code where my chatbox processes the keyboard input:

public void pollKeyboardInput(int keyCode, char keyChar, boolean keyReleased) {
    if (!keyReleased) { // I've tried toggling this value, but still just gets spammed..
   //Reads the same character massive amount of times, unless I tap the key quickly?
   inputString = TextFormatter.formatInputString(inputString, keyCode, keyChar, 50, Keyboard.KEY_BACK);

NOTE: I’ve tried a bunch of solutions and nothing seems to work… when I dont use Keyboard.next() it spams my chatbox with the same character (unless I tap the key quickly), and when I do use Keyboard.next() it doesnt read any input at all…

My assumption is that the JME lib has the while (Keyboard.next()) { code being called internally, can I disable this somehow? What will the consequences be; will it break the ActionListener feature? Is there a better solution? I hope I provided enough details.

Edited the post a bunch of times for clarity and to provide enough information.

So, you did that part wrong. Let’s go back to that because Keyboard.next() in the main loop is 100% not the right way to go.

Register a raw input listener with the input manager and catch the key events.


Works, thank you for the help @pspeed

1 Like