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 one of these methods:
- Use the key's accessor property, such
Keyboard.spaceKey. - Use the
Keyboardclass' indexer and theKeyenumeration (for example,keyboard[Key.Space]).
Look up keys based on the character they produce
To look up keys based on the character they produce, use Control paths. For example, you can query the key that produces the producing the a character from Keyboard using Keyboard.current\["\#(a)"\].
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.
Keyboard.current.FindKeyOnCurrentKeyboardLayout("q");
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
QWERTkeys correctly, but might not reportQWERAcorrectly. - 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
Keyboarddevices at any point, platform backends generally only report a single keyboard and route input from all attached keyboards to the one keyboard device.