Search Unity

Keyboard mapping messed up?

Discussion in 'Linux' started by phrobion, Jul 28, 2020.

  1. phrobion

    phrobion

    Joined:
    Mar 10, 2017
    Posts:
    34
    Hello everyone.

    [EDIT]: Found out the problem below does only exist in Unitys in-editor-gameview.
    On a standalone game-build the keyboard is mapped correct.
    Easiest way to get a console-output is to enable "Development build" in build-settings and use Debug.LogError(...) instead of Debug.Log(...).

    Problem:
    It all started when I tried to use the "space"-Key with Input.GetKey() (or Input.GetKeyDown())

    Code (CSharp):
    1. // Update is called once per frame
    2.     void Update()
    3.     {
    4.  
    5.         // working
    6.         if (Input.GetKeyDown(KeyCode.X))
    7.         {
    8.             Debug.Log("X Key Pressed");
    9.         }
    10.         // working
    11.         if (Input.GetKeyDown(KeyCode.LeftShift))
    12.         {
    13.             Debug.Log("LeftShift Key Pressed");
    14.         }
    15.         // working
    16.         if (Input.GetKeyDown(KeyCode.Return))
    17.         {
    18.             Debug.Log("Return Key Pressed");
    19.         }
    20.         // working
    21.         if (Input.GetKeyDown(KeyCode.Escape))
    22.         {
    23.             Debug.Log("Escape Key Pressed");
    24.         }
    25.  
    26.         // NOT working
    27.         if (Input.GetKeyDown(KeyCode.Space))
    28.         {
    29.             Debug.Log("Space Key Pressed");
    30.         }
    31.         // NOT working
    32.         if (Input.GetKeyDown("space"))
    33.         {
    34.             Debug.Log("Space Key Pressed");
    35.         }
    36.         // NOT working
    37.         if (Input.GetKey(KeyCode.Space))
    38.         {
    39.             Debug.Log("Space Key Pressed");
    40.         }
    41.         // NOT working
    42.         if (Input.GetKey("space"))
    43.         {
    44.             Debug.Log("Space Key Pressed");
    45.         }
    46.  
    47.     }
    Whatever I tried, i didn't make the "spacebar" working.
    So I added a function to test my Keyboard-Mapping:

    Code (CSharp):
    1. void OnGUI()
    2.     {
    3.         Event e = Event.current;
    4.         if (e.isKey)
    5.         {
    6.             Debug.Log("Detected key code: " + e.keyCode);
    7.         }
    8.     }
    Found out, my spacebar is mapped to an "O".
    Also my numbers (the row obove the letters on keyboard are not mapped correct.
    Leftshift, Escape, Return, Letters, ... everything working.

    My big question: why?
    My keyboard is working fine in Unity-Editor and VSCode (would be hard to code if not).
    What am I missing, what am I doing wrong?

    Thanks in advance.

    Unity 2019.4 (LTS)
    Opensuse 15.2
     
    Last edited: Jul 28, 2020
    Nevermiss likes this.