[LibGDX] Getting raw keyboard input

Hey guys,

I’m trying to make a sort of text-field GUI and I can’t figure out how to get the pure raw data from the keyboard without making a listener for each and every key. I’ve been searching for quite some time.

To clarify, I need a way to get keyboard input and put it into a String without writing functions for each individual key.

Thanks

Scanner…

EDIT: I should be more clear:

In a hand-coded GUI, you would use switch-case a key press event and for each event, put down the font sprite of the letter.

LibGDX has it’s own way of handling text input:

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/TextField.html

along with a few others that are better suited for whatever task you need (if you were porting your program for instance, TextInputListener would be better suited to that problem.) As BurntPizza mentioned, you could keyTyped() too, or you could use Scanner.

Since you have this tagged as libGDX, you could use an InputProcessor:


@Override
public boolean keyTyped(int keycode) {
    stringBuilder.append(Input.Keys.toString(keycode));
}

Gdx.input.isKeyPressed(Keys.) for quick polling. Why would you ever need a separate listener for each key?

Using polling is highly discouraged for text input, as you’re guaranteed to lose events - increasingly so with lower framerates.

Oh, I didn’t read the post in detail, didn’t know it was for textfields :emo:

I ended up using a modified version of this