Skip to content

Latest commit

 

History

History
39 lines (23 loc) · 2.86 KB

File metadata and controls

39 lines (23 loc) · 2.86 KB
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 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 Keyboard class' indexer and the 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. 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 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.