Enum Key
Enumeration of key codes.
Namespace: UnityEngine.InputSystem
Assembly: Unity.InputSystem.dll
Syntax
public enum Key
Remarks
Named according to the US keyboard layout which is used as a reference layout.
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.
// Look up key by key code.
var aKey = Keyboard.current[Key.A];
// Find out which text is produced by the key.
Debug.Log($"The '{aKey.keyCode}' key produces '{aKey.displayName}' as text input");
Fields
Name | Description |
---|---|
A | The aKey. |
AltGr | Same as RightAlt. |
B | The bKey. |
Backquote | The backquoteKey. |
Backslash | The backslashKey. |
Backspace | The backspaceKey. |
C | The cKey. |
CapsLock | The capsLockKey. |
Comma | The commaKey. |
ContextMenu | The contextMenuKey. |
D | The dKey. |
Delete | The deleteKey. |
Digit0 | The digit0Key. |
Digit1 | The digit1Key. |
Digit2 | The digit2Key. |
Digit3 | The digit3Key. |
Digit4 | The digit4Key. |
Digit5 | The digit5Key. |
Digit6 | The digit6Key. |
Digit7 | The digit7Key. |
Digit8 | The digit8Key. |
Digit9 | The digit9Key. |
DownArrow | The downArrowKey. |
E | The eKey. |
End | The endKey. |
Enter | The enterKey. |
Equals | The equalsKey. |
Escape | The escapeKey. |
F | The fKey. |
F1 | The f1Key. |
F10 | The f10Key. |
F11 | The f11Key. |
F12 | The f12Key. |
F2 | The f2Key. |
F3 | The f3Key. |
F4 | The f4Key. |
F5 | The f5Key. |
F6 | The f6Key. |
F7 | The f7Key. |
F8 | The f8Key. |
F9 | The f9Key. |
G | The gKey. |
H | The hKey. |
Home | The homeKey. |
I | The iKey. |
IMESelected | |
Insert | The insertKey. |
J | The jKey. |
K | The kKey. |
L | The lKey. |
LeftAlt | The leftAltKey. |
LeftApple | Same as LeftMeta. |
LeftArrow | The leftArrowKey. |
LeftBracket | The leftBracketKey. |
LeftCommand | Same as LeftMeta. |
LeftCtrl | The leftCtrlKey. |
LeftMeta | The leftMetaKey. |
LeftShift | The leftShiftKey. |
LeftWindows | Same as LeftMeta. |
M | The mKey. |
Minus | The minusKey. |
N | The nKey. |
None | Invalid key. Does not represent a key on the keyboard and is only used to have a default for the Key enumeration not represent any specific key. |
NumLock | The numLockKey. |
Numpad0 | The numpad0Key. |
Numpad1 | The numpad1Key. |
Numpad2 | The numpad2Key. |
Numpad3 | The numpad3Key. |
Numpad4 | The numpad4Key. |
Numpad5 | The numpad5Key. |
Numpad6 | The numpad6Key. |
Numpad7 | The numpad7Key. |
Numpad8 | The numpad8Key. |
Numpad9 | The numpad9Key. |
NumpadDivide | The numpadDivideKey. |
NumpadEnter | The numpadEnterKey. |
NumpadEquals | The numpadEqualsKey. |
NumpadMinus | The numpadMinusKey. |
NumpadMultiply | The numpadMultiplyKey. |
NumpadPeriod | The numpadPeriodKey. |
NumpadPlus | The numpadPlusKey. |
O | The oKey. |
OEM1 | The oem1Key. |
OEM2 | The oem2Key. |
OEM3 | The oem3Key. |
OEM4 | The oem4Key. |
OEM5 | The oem5Key. |
P | The pKey. |
PageDown | The pageDownKey. |
PageUp | The pageUpKey. |
Pause | The pauseKey. |
Period | The periodKey. |
PrintScreen | The printScreenKey. |
Q | The qKey. |
Quote | The quoteKey. |
R | The rKey. |
RightAlt | The rightAltKey. |
RightApple | Same as RightMeta. |
RightArrow | The rightArrowKey. |
RightBracket | The rightBracketKey. |
RightCommand | Same as RightMeta. |
RightCtrl | The rightCtrlKey. |
RightMeta | The rightMetaKey. |
RightShift | The rightShiftKey. |
RightWindows | Same as RightMeta. |
S | The sKey. |
ScrollLock | The scrollLockKey. |
Semicolon | The semicolonKey. |
Slash | The slashKey. |
Space | The spaceKey. |
T | The tKey. |
Tab | The tabKey. |
U | The uKey. |
UpArrow | The upArrowKey. |
V | The vKey. |
W | The wKey. |
X | The xKey. |
Y | The yKey. |
Z | The zKey. |