I'm looking for a solution to receive text input through LWJGL. I'm not referring to the kind of standard keyboard event input offered by LWJGL, I'm looking for the ability to receive actual lines of text input, much like the TextFields offered by AWT/Swing. I'm doing this mostly in the interest of learning, and as such, I have no interest in using a library outside of LWJGL (such as TWL).
Currently, I have something like this:
private boolean shift = false;
private void chatControls(float ticksPassed) {
while (Keyboard.next()) {
if (Keyboard.isKeyDown(Keyboard.KEY_RETURN)) {
this.ui.toggleChat();
} else if (Keyboard.isKeyDown(Keyboard.KEY_DELETE)) {
this.chatText = "";
} else if (Keyboard.isKeyDown(Keyboard.KEY_BACK) && Keyboard.getEventKeyState()) {
try {
this.chatText = this.chatText.substring(0, chatText.length() - 1);
} catch (StringIndexOutOfBoundsException e) {}
} else if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
shift = Keyboard.getEventKeyState();
} else if (Keyboard.getEventKeyState() && !jtLetter) {
if (shift) {
this.chatText += Character.toUpperCase(Keyboard.getEventCharacter());
} else {
this.chatText += String.valueOf(Keyboard.getEventCharacter());
jtLetter = true;
}
} else {
jtLetter = false;
}
this.ui.updateChat(chatText);
}
}
However, it does not manage to properly handle shift, nor any of the other special commands described above. So, what's the best thing to do?
Take a look at this file of the source code of NiftyGUI, which should contain this text handling code.