Files
Test/Library/PackageCache/com.unity.inputsystem@2436e68c60c4/Documentation~/query-keyboards.md
T
2026-11-01 23:39:55 +02:00

40 lines
2.9 KiB
Markdown

---
uid: input-system-query-keyboard
---
# Query keyboard devices in code
To query which (if any) character is generated by a given key, use the key control's [`displayName`](xref:UnityEngine.InputSystem.InputControl.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`](xref:UnityEngine.InputSystem.Keyboard) device, use one of these methods:
* Use the key's accessor property, such [`Keyboard.spaceKey`](xref:UnityEngine.InputSystem.Keyboard.spaceKey).
* Use the [`Keyboard`](xref:UnityEngine.InputSystem.Keyboard) class' indexer and the [`Key`](xref:UnityEngine.InputSystem.Key) enumeration (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](control-paths.md). For example, you can query the key that produces the producing the a character from [`Keyboard`](xref:UnityEngine.InputSystem.Keyboard) using [`Keyboard.current\["\#(a)"\]`](xref:UnityEngine.InputSystem.Keyboard.Item(UnityEngine.InputSystem.Key)).
## Look up keyboard layouts
To query the name of the current keyboard layout use [`Keyboard.keyboardLayout`](xref:UnityEngine.InputSystem.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`](xref:UnityEngine.InputSystem.InputSystem.onDeviceChange) and check for [`InputDeviceChange.ConfigurationChanged`](xref:UnityEngine.InputSystem.InputDeviceChange) on a [`Keyboard`](xref:UnityEngine.InputSystem.Keyboard) device.
To find the key control that corresponds to a specific display character sequence, call [`Keyboard.FindKeyOnCurrentKeyboardLayout`](xref:UnityEngine.InputSystem.Keyboard.FindKeyOnCurrentKeyboardLayout*):
```c#
// 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 `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`](xref:UnityEngine.InputSystem.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.