Special characters in libgdx's textfield do not work
java, libgdx, macos, special-characters, textfield
Solution
UPDATE
It seems, that this is related to a bug with unicode characters in lwjgl on OSX: [FIXED] Unicode input
If you update to the latest lwjgl library 2.9.1 this should be fixed. From the changelog:
2013-10-13 kappaOne
- .../org/lwjgl/opengl/MacOSXNativeKeyboard.java, src/native/macosx/org_lwjgl_opengl_Display.m: Fix keyboard key codes to return Unicode characters instead of ASCII characters
see: 2.9.1-changelog.txt
Original Answer
How do you get input from special characters in Libgdx?
You can implement the interface com.badlogic.gdx.InputProcessor and set the current input processor by calling `Gdx.input.setInputProcessor(inputProcessor );`
Then you should be able to receive notifications about all typed characters (special or not) in the method InputProcessor#keyTyped(char c).
Actually this is more or less, what the class TextField does (not exactly, it listens for input by extending com.badlogic.gdx.scenes.scene2d.InputListener).
I had a quick look at the relevant source code of TextFields keyTyped method:
[...]
if (font.containsCharacter(character)) {
// here the character gets added to the text field
}
[...]
So it seems, that the font of the text field must support the character, otherwise it will not be displayed. I have no mac to test this, but I would guess, that the BitmapFont used by default on your mac does not support the special characters. Try to set a different BitmapFont for the TextField (see TextField.setStyle(TextFieldStyle style)) and see if this solves the problem.
Problem
I can use setText("åäö") but if I type on my keyboard it doesn't show up, this doesn't work either ``` public void keyTyped(TextField textField, char key) { JOptionPane.showMessageDialog(new JFrame(), key); } ``` The strange thing is that it doesn't work on mac but it does work on Windows, does anyone have an answer for that? Thank You! Here's another question with a similarly topic! How do you get input from special characters in Libgdx? I have tried to get the ascii value and puting it through ``` Gdx.input.isKeyPressed(ascii value); ``` but it doesn't work. I have set my project encoding to UTF-8 and I can print special characters like åäö. Edit: I tried this ``` Gdx.input.setInputProcessor(new InputProcessor() { @Override public boolean keyDown(int keycode) { // TODO Auto-generated method stub return false; } @Override public boolean keyUp(int keycode) { // TODO Auto-generated method stub return false; } @Override public boolean keyTyped(char character) { System.out.println(character); return false; } @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { return false; } @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { return false; } @Override public boolean touchDragged(int screenX, int screenY, int pointer) { return false; } @Override public boolean mouseMoved(int screenX, int screenY) { return false; } @Override public boolean scrolled(int amount) { return false; } }); ``` Didn't print åäö