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:
@Override
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());
}
//client.pollKeyboardInput(keysDown);
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..
return;
}
//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.