Class KeyControl
A key on a Keyboard.
Inherited Members
Namespace: UnityEngine.InputSystem.Controls
Syntax
public class KeyControl : ButtonControl
Remarks
This is an extended button control which adds various features to account for the fact that keys have symbols associated with them which may change depending on keyboard layout as well as in combination with other keys.
Note: Unity input system key codes and input manager key codes are designed with game controls in mind.
This means the way they are assigned is intended to preserve the location of keys on keyboards, so that pressing a key in the same location on different keyboards should result in the same action regardless of what is printed on a key or what current system language is set.
This means, for example, that A is always the key to the right of CapsLock, regardless of which key (if any) produces the "a" character on the current keyboard layout.
Unity relies on physical hardware in the keyboards to report same USB HID "usage" for the keys in the same location.This puts a practical limit on what can be achieved, because different keyboards might report different data, and this is outside of Unity's control.
For this reason, you should not use key codes to read text input.
Instead, you should use the onTextInput callback.
The onTextInput
callback provides you with the actual text characters which correspond
to the symbols printed on a keyboard, based on the end user's current system language layout.
To find the text character (if any) generated by a key according to the currently active keyboard layout, use the displayName property of KeyControl.
Properties
keyCode
The code used in Unity to identify the key.
Declaration
public Key keyCode { get; set; }
Property Value
Type | Description |
---|---|
Key |
Remarks
This property must be initialized by FinishSetup() of
the device owning the control.
You should not use keyCode
to read text input. For more information, KeyControl
scanCode
The code that the underlying platform uses to identify the key.
Declaration
public int scanCode { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
RefreshConfiguration()
Declaration
protected override void RefreshConfiguration()