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 Caps
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 ononTextInput
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 display
// 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 a |
AltGr | Same as Right |
B | The b |
Backquote | The backquote |
Backslash | The backslash |
Backspace | The backspace |
C | The c |
CapsLock | The caps |
Comma | The comma |
ContextMenu | The context |
D | The d |
Delete | The delete |
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 down |
E | The e |
End | The end |
Enter | The enter |
Equals | The equals |
Escape | The escape |
F | The f |
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 g |
H | The h |
Home | The home |
I | The i |
IMESelected | |
Insert | The insert |
J | The j |
K | The k |
L | The l |
LeftAlt | The left |
LeftApple | Same as Left |
LeftArrow | The left |
LeftBracket | The left |
LeftCommand | Same as Left |
LeftCtrl | The left |
LeftMeta | The left |
LeftShift | The left |
LeftWindows | Same as Left |
M | The m |
Minus | The minus |
N | The n |
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 num |
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 numpad |
NumpadEnter | The numpad |
NumpadEquals | The numpad |
NumpadMinus | The numpad |
NumpadMultiply | The numpad |
NumpadPeriod | The numpad |
NumpadPlus | The numpad |
O | The o |
OEM1 | The oem1Key. |
OEM2 | The oem2Key. |
OEM3 | The oem3Key. |
OEM4 | The oem4Key. |
OEM5 | The oem5Key. |
P | The p |
PageDown | The page |
PageUp | The page |
Pause | The pause |
Period | The period |
PrintScreen | The print |
Q | The q |
Quote | The quote |
R | The r |
RightAlt | The right |
RightApple | Same as Right |
RightArrow | The right |
RightBracket | The right |
RightCommand | Same as Right |
RightCtrl | The right |
RightMeta | The right |
RightShift | The right |
RightWindows | Same as Right |
S | The s |
ScrollLock | The scroll |
Semicolon | The semicolon |
Slash | The slash |
Space | The space |
T | The t |
Tab | The tab |
U | The u |
UpArrow | The up |
V | The v |
W | The w |
X | The x |
Y | The y |
Z | The z |