Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GetBindingDisplayString returns non English names when the player's keyboard is set to non English

Discussion in 'Input System' started by DoctorShinobi, Apr 6, 2022.

  1. DoctorShinobi

    DoctorShinobi

    Joined:
    Oct 5, 2012
    Posts:
    219
    Does anyone else have this issue? I'm using GetBindingDisplayString() on an InputAction that has its 0 index binding set to a key such as C/X/Z. When the player's keyboard language is currently set to something other than English I get the name of the key in that specific language. Players don't expect this behavior, and it causes issues with fonts that only support English.

    Does anyone know a way to get around this?
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    This is by design so that the resulting string reflects the keys as they actually appear on the player's keyboard.

    The only alternative ATM in terms of built-in mechanisms is to convert the raw binding string and disregard the actual control it leads to (which is where the locale-dependent string is coming from here). ATM can't be done with a
    DisplayStringOption
    (might be a useful thing to add) but can be done by using
    ToDisplayString
    on a binding.

    Code (CSharp):
    1. var action = new InputAction(binding: "<Keyboard>/a");
    2.  
    3. // Invariably prints "A" even if "A" is actually a different key
    4. // on the player's keyboard.
    5. Debug.Log(action.bindings[0].ToDisplayString());
    As for getting an English-language string for the locale-dependent keyboard key, off the top of my head, the only thing I could think of being readily available is to convert the Unicode characters to their Unicode names. Doubt that is crazy useful but it'd make sure you'd end up with Latin alphabet characters only.
     
    Demexis and DoctorShinobi like this.
  3. DoctorShinobi

    DoctorShinobi

    Joined:
    Oct 5, 2012
    Posts:
    219
    Thanks. It would be nice in the future to be able to choose the current behavior or to have an easy way to force it to be English. I don't know how most games handle non-QWERTY keyboards, but usually games display the key names in the same language as the UI is localized to.
     
    rubendariohh likes this.
  4. rubendariohh

    rubendariohh

    Joined:
    Oct 14, 2017
    Posts:
    32
    Same issue here and this was my completely rudimentary implementation :oops:

    Code (CSharp):
    1.  cameraInputDown = playerInput.actions["Camera"].GetBindingDisplayString(3);
    2.  
    3.         if (cameraInputDown == "Flecha Abajo" || cameraInputDown == "Nach-Unten" || cameraInputDown == "Bas"
    4.             || cameraInputDown == "Seta Abaixo")
    5.         {
    6.             cameraInputDown = "Down";
    7.         }

    Apart from having to do something similar for all key actions per language obviously it wouldn't work for non-latin alphabets...