Special characters in libgdx's textfield do not work

前端 未结 1 1671
谎友^
谎友^ 2020-12-21 01:33

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 t         


        
相关标签:
1条回答
  • 2020-12-21 02:01

    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.

    0 讨论(0)
提交回复
热议问题