Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to display the effective key with the current keyboard?

Discussion in 'Input System' started by dlorre, Jul 13, 2023.

  1. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    So, I have 2 input actions for switching to the next panel and to the previous panel. So far, so good. NextPanel is bound to E and PreviousPanel is bound to Q.

    But, when I switch to French Keyboard, NextPanel is still E but PreviousPanel becomes A. It's the same key on the keyboard it's just that French keyboard is AZERTY and English keyboard is QWERTY.

    What I want to do, is to display on the status bar that the user should press Q (or A if French keyboard) to go to the previous panel. How can I do this?

    Code (csharp):
    1.  
    2.             controls.PlayMenu.NextPanel.performed += nextPanel;
    3.             controls.PlayMenu.PreviousPanel.performed += previousPanel;
    4.  
    Using localization won't work flawlessly because the user might be in French locale and switch to English keyboard.

    upload_2023-7-13_15-47-37.png


    So, is there a functionality to display the effective keyboard key for the input action controls.PlayMenu.PreviousPanel?
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    Check out the docs.

    InputAction.GetBindingDisplayString
    , check out the sample code in the section I linked above.
     
  3. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    Thanks but that does not work:

    Code (csharp):
    1.  
    2.             controls.PlayMenu.PreviousPanel.performed += previousPanel;
    3.             foreach (var b in controls.PlayMenu.PreviousPanel.bindings)
    4.             {
    5.                 Debug.Log(b.ToDisplayString());
    6.             }
    7.  
    upload_2023-7-13_16-14-27.png

    I want 'A' not 'Q', if I tell the users to press Q to go to previous panel they will tell me that it does not work. I guess I will use localization then, only a minority will be affected.
     
  4. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    How about using N(ext) and P(revious). They are the same on every keyboard, I think.
     
  5. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    That's an interesting idea but Q & E are quite ergonomics since they are near WASD, another alternative is Insert & Pg Up, but that won't work too well on laptops with small keyboards.