For my first one attempt at a chat box, I created a ChatBox class, when enter is pressed, the input is disabled in the game, and only will only work in the ChatBox class.
using org.lwjgl.input.Keyboard class I have a method
public char getChatKey(){
return Keyboard.getEventCharacter();
}
which is inside my InputHandler class.
in my ChatBox class, I have an array of char’s (because i get random chars in the way if I don’t), I loop through the allowed keys if the key matches one of the chars in the array, it is then applied to the message string.
char key = input.getChatKey();
for (int i = 0; i < allowedKeys.length; i++) {
if (key == allowedKeys[i]) {
message += key;
}
}
You may also want to put a delay in their so 5000 of the same keys don’t instantly get put in. or some other way of checking to make sure unwanted amounts of the same key is entered.
EDIT: added more