docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Query keyboard devices in code

    To query which (if any) character is generated by a given key, use the key control's displayName property. The value of this property changes automatically when the operating system changes the keyboard layout.

    Look up keys

    To retrieve a key from a Keyboard device, use the key's accessor property, such as Keyboard.spaceKey.

    Look up keys based on the character they produce

    To look up keys based on the character they produce, use Control paths. For example, Keyboard.current["#(a)"] returns the key that produces the "a" character on the current keyboard layout. For more information about the string indexer, refer to InputControl.Item.

    Look up keyboard layouts

    To query the name of the current keyboard layout use Keyboard.keyboardLayout. Layout names are platform-specific. There's no support for setting keyboard layouts from your application.

    To monitor keyboard layout changes, hook into InputSystem.onDeviceChange and check for InputDeviceChange.ConfigurationChanged on a Keyboard device.

    To find the key control that corresponds to a specific display character sequence, call Keyboard.FindKeyOnCurrentKeyboardLayout:

    // Find key that generates a 'q' character according to the current keyboard layout.
    var qKey = Keyboard.current.FindKeyOnCurrentKeyboardLayout("q");
    

    Detect the Android back button

    On Android, the Input System reports the system back button as the Escape key of the Keyboard device. To detect it, read Keyboard.escapeKey:

    // On Android, the Input System reports the back button as the Escape key.
    var keyboard = Keyboard.current;
    if (keyboard != null && keyboard.escapeKey.wasPressedThisFrame)
    {
        // Respond to the back button. For example, open a pause menu.
    }
    

    To respond to the back button with an action, bind the action to <Keyboard>/escape.

    Keyboard limitations

    • Keyboards usually have hardware limitations on both the number of simultaneous keypresses they report, and the combinations of keys they support. This means that certain simultaneous keypresses might not register correctly. For example, a given keyboard might report a simultaneous press of the QWERT keys correctly, but might not report QWERA correctly.
    • The Input System doesn't support on-screen keyboards. Instead, use UnityEngine.TouchScreenKeyboard.
    • Unity platform backends generally don't support distinguishing between multiple keyboards. While the Input System supports having many Keyboard devices at any point, platform backends generally only report a single keyboard and route input from all attached keyboards to the one keyboard device.
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)