Issues with Input.inputString

Hey folks!

I have some issues when using Input.inputString – when I am getting an user input (Input.anyKeyDown) and Debug.Log the Input.inputString, it works perfectly fine with the standard keys like a–z or 1–0. But using the ESC and arrow keys will result either in an empty string or jibberish.

I am using Unity 2018.1.1 on a MacBook Pro with MacOS 10.13.6.

Anybody having the same issues or knows how to fix it? I need the Input.inputString to return exactly the key pressed for individualising the keyboard layout for a player.

Thanks in advance for your reply!

Input.inputString is not designed to return the pressed key, (otherwise it would be returning a keycode), it’s designed to return the text that the pressed keys would write into a text field. Escape and the arrow keys don’t write anything so the inputstring is empty, the inputstring for Return should be "
", etc…

In order to achieve you seek, I think you need to look into the Event class instead of Input. The snippet of code on this page seems to do just that :

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void OnGUI() {
        Event e = Event.current;
        if (e.isKey)
            Debug.Log("Detected key code: " + e.keyCode);
        
    }
}

@Minoangelo

According to the docs Input.inputString can be used for ASCII characters and the backspace and return keys only.