Class Keyboard
Represents a standard, physical PC-type keyboard.
Implements
Inherited Members
Namespace: UnityEngine .InputSystem
Assembly: Unity.InputSystem.dll
Syntax
public class Keyboard : InputDevice, ITextInputReceiver
Remarks
Keyboards allow for both individual button input as well as text input. To receive button
input, use the individual Key
The naming/identification of keys is agnostic to keyboard layouts. This means that a"<Keyboard>/a"
on an Input
To find what text character (if any) is produced by a key, you can use the key's display"<Keyboard>/#(a)"
, for example, will bind to the key that produces the "a"
character according to the currently active keyboard layout.
To find out which keyboard layout is currently active, you can use the keyboard
Note that keyboard devices will always have key controls added for all keys in the Key enumeration -- whether they are actually present on the physical keyboard or not. It is thus not possible to find out this way whether the underlying keyboard has certain keys or not.
Examples
using UnityEngine;
using UnityEngine.InputSystem;
public class InputExample : MonoBehaviour
{
private string inputText = "";
void Start()
{
Keyboard.current.onTextInput += OnTextInput;
}
void Update()
{
// Check whether the A key on the current keyboard is pressed.
if (Keyboard.current.aKey.wasPressedThisFrame)
Debug.Log("A Key pressed");
}
private void OnTextInput(char ch)
{
inputText += ch;
}
}
Fields
KeyCount
Total number of key controls on a keyboard, i.e. the number of controls
in all
Declaration
public const int KeyCount = 110
Field Value
Type | Description |
---|---|
int |
See Also
Properties
this[Key]
Look up a key control by its key code.
Declaration
public KeyControl this[Key key] { get; }
Parameters
Type | Name | Description |
---|---|---|
Key | key | Key code of key control to return. |
Property Value
Type | Description |
---|---|
Key |
Remarks
This is equivalent to allKeys[(int)key - 1]
.
Exceptions
Type | Condition |
---|---|
Argument |
The given |
See Also
aKey
The 'a' key. The key immediately to the right of caps
Declaration
public KeyControl aKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
allKeys
List of all key controls on the keyboard.
Declaration
public ReadOnlyArray<KeyControl> allKeys { get; }
Property Value
Type | Description |
---|---|
Read |
See Also
altKey
An artificial combination of left
Declaration
public ButtonControl altKey { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
Remarks
Button
This is a synthetic button which is considered pressed whenever the left and/or right alt key is pressed.
See Also
anyKey
A synthetic button control that is considered pressed if any key on the keyboard is pressed.
Declaration
public AnyKeyControl anyKey { get; protected set; }
Property Value
Type | Description |
---|---|
Any |
Remarks
Any
See Also
bKey
The 'b' key. The key in-between the v
Declaration
public KeyControl bKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
backquoteKey
The ` key. The leftmost key in the row of digits. Directly above tab
Declaration
public KeyControl backquoteKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
backslashKey
The '' key. The key immediately to the right of right
Declaration
public KeyControl backslashKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
backspaceKey
The backspace key (usually labeled "delete" on Mac). The rightmost key
in the top digit row with equals
Declaration
public KeyControl backspaceKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
On the Mac, this key may be labeled "delete" which however is a
key different from delete
See Also
cKey
The 'c' key. The key in-between the x
Declaration
public KeyControl cKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
capsLockKey
The Caps Lock key. The key below tab
Declaration
public KeyControl capsLockKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
commaKey
The ',' key. Third key to the left of right
Declaration
public KeyControl commaKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
contextMenuKey
The context menu key. This key is generally only found on PC keyboards.
If present, it is located in-between the right
Declaration
public KeyControl contextMenuKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
ctrlKey
An artificial combination of left
Declaration
public ButtonControl ctrlKey { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
Remarks
Button
This is a synthetic button which is considered pressed whenever the left and/or right ctrl key is pressed.
See Also
current
The keyboard that was last used or added. Null if there is no keyboard.
Declaration
public static Keyboard current { get; }
Property Value
Type | Description |
---|---|
Keyboard |
See Also
dKey
The 'd' key. The key in-between the s
Declaration
public KeyControl dKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
deleteKey
The 'delete' key. Usually in a separate block with end
Declaration
public KeyControl deleteKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
On the Mac, the backspace
See Also
digit0Key
The '0' key. The key in-between the digit9Key to the left and the minus
Declaration
public KeyControl digit0Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
digit1Key
The '1' key. The key in-between the backquote
Declaration
public KeyControl digit1Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
digit2Key
The '2' key. The key in-between the digit1Key to the left and the digit3Key to the right in the row of digit characters.
Declaration
public KeyControl digit2Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
digit3Key
The '3' key. The key in-between the digit2Key to the left and the digit4Key to the right in the row of digit characters.
Declaration
public KeyControl digit3Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
digit4Key
The '4' key. The key in-between the digit3Key to the left and the digit5Key to the right in the row of digit characters.
Declaration
public KeyControl digit4Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
digit5Key
The '5' key. The key in-between the digit4Key to the left and the digit6Key to the right in the row of digit characters.
Declaration
public KeyControl digit5Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
digit6Key
The '6' key. The key in-between the digit5Key to the left and the digit7Key to the right in the row of digit characters.
Declaration
public KeyControl digit6Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
digit7Key
The '7' key. The key in-between the digit6Key to the left and the digit8Key to the right in the row of digit characters.
Declaration
public KeyControl digit7Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
digit8Key
The '8' key. The key in-between the digit7Key to the left and the digit9Key to the right in the row of digit characters.
Declaration
public KeyControl digit8Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
digit9Key
The '9' key. The key in-between the digit8Key to the left and the digit0Key to the right in the row of digit characters.
Declaration
public KeyControl digit9Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
downArrowKey
The down arrow key. Usually in a block by itself and generally below the
up
Declaration
public KeyControl downArrowKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
eKey
The 'e' key. The key in-between the w
Declaration
public KeyControl eKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
endKey
The 'end' key. Usually in a separate block with delete
Declaration
public KeyControl endKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
enterKey
The enter/return key in the main key block.
Declaration
public KeyControl enterKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
equalsKey
The '=' key in the main key block. The key in-between minus
Declaration
public KeyControl equalsKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
escapeKey
The escape key, i.e. the key generally in the top left corner of the keyboard. Usually to the left of f1Key.
Declaration
public KeyControl escapeKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f10Key
The F10 key. The key in-between f9Key to the left and f11Key to the right in the topmost row of keys.
Declaration
public KeyControl f10Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f11Key
The F11 key. The key in-between f10Key to the left and f12Key to the right in the topmost row of keys.
Declaration
public KeyControl f11Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f12Key
The F12 key. The key in-between f11Key to the left and print
Declaration
public KeyControl f12Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f1Key
The F1 key. The key in-between escape
Declaration
public KeyControl f1Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f2Key
Declaration
public KeyControl f2Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f3Key
Declaration
public KeyControl f3Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f4Key
Declaration
public KeyControl f4Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f5Key
Declaration
public KeyControl f5Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f6Key
Declaration
public KeyControl f6Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f7Key
Declaration
public KeyControl f7Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f8Key
Declaration
public KeyControl f8Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
f9Key
The F9 key. The key in-between f8Key to the left and f10Key to the right in the topmost row of keys.
Declaration
public KeyControl f9Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
fKey
The 'f' key. The key in-between the d
Declaration
public KeyControl fKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
gKey
The 'g' key. The key in-between the f
Declaration
public KeyControl gKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
hKey
The 'h' key. The key in-between the g
Declaration
public KeyControl hKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
homeKey
Declaration
public KeyControl homeKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
iKey
The 'i' key. The key in-between the u
Declaration
public KeyControl iKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
imeSelected
True when IME composition is enabled. Requires Set
Declaration
public ButtonControl imeSelected { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
Remarks
Some languages use complex input methods which involve opening windows to insert characters. Typically, this is not desirable while playing a game, as games may just interpret keystrokes as game input, not as text.
See Set
See Also
insertKey
The 'insert' key. Usually in a separate block with home
Declaration
public KeyControl insertKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
jKey
The 'j' key. The key in-between the h
Declaration
public KeyControl jKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
kKey
The 'k' key. The key in-between the j
Declaration
public KeyControl kKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
keyboardLayout
The name of the layout currently used by the keyboard.
Declaration
public string keyboardLayout { get; protected set; }
Property Value
Type | Description |
---|---|
string |
Remarks
Note that keyboard layout names are platform-specific.
The value of this property reflects the currently used layout and thus changes whenever the layout of the system or the one for the application is changed.
To determine what a key represents in the current layout, use display
See Also
keys
Raw array of key controls on the keyboard.
Declaration
protected KeyControl[] keys { get; set; }
Property Value
Type | Description |
---|---|
Key |
See Also
lKey
The 'l' key. The key in-between the k
Declaration
public KeyControl lKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
leftAltKey
The alt/option key on the left side of the keyboard.
Declaration
public KeyControl leftAltKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
leftAppleKey
Same as left
Declaration
public KeyControl leftAppleKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
leftArrowKey
The left arrow key. Usually in a block by itself and generally to the left
of down
Declaration
public KeyControl leftArrowKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
leftBracketKey
The '[' key. The key immediately to the left of right
Declaration
public KeyControl leftBracketKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
leftCommandKey
Same as left
Declaration
public KeyControl leftCommandKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
leftCtrlKey
The control/ctrl key on the left side of the keyboard.
Declaration
public KeyControl leftCtrlKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
leftMetaKey
The system "meta" key (Windows key on PC, Apple/command key on Mac) on the left side of the keyboard.
Declaration
public KeyControl leftMetaKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
leftShiftKey
The shift key on the left side of the keyboard.
Declaration
public KeyControl leftShiftKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
leftWindowsKey
Same as left
Declaration
public KeyControl leftWindowsKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
mKey
The 'm' key. The key in-between the n
Declaration
public KeyControl mKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
minusKey
The '-' key. The second key to the left of backspace
Declaration
public KeyControl minusKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
nKey
The 'n' key. The key in-between the b
Declaration
public KeyControl nKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numLockKey
The Num Lock key. The key sitting in the top left corner of the numpad and which usually toggles the numpad between generating digits and triggering functions like "insert" etc. instead.
Declaration
public KeyControl numLockKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpad0Key
The 0 key on the numpad. The key in the bottom left corner of the numpad. Usually and elongated key.
Declaration
public KeyControl numpad0Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpad1Key
The 1 key on the numpad. The key on the left side of the numpad with numpad0Key below it and numpad4Key above it.
Declaration
public KeyControl numpad1Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpad2Key
The 2 key on the numpad. The key with the numpad1Key to its left and the numpad3Key to its right.
Declaration
public KeyControl numpad2Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpad3Key
The 3 key on the numpad. The key with the numpad2Key to its left and
the numpad
Declaration
public KeyControl numpad3Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpad4Key
The 4 key on the numpad. The key on the left side of the numpad with the numpad1Key below it and the numpad7Key above it.
Declaration
public KeyControl numpad4Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpad5Key
The 5 key on the numpad. The key in-between the numpad4Key to the left and the numpad6Key to the right.
Declaration
public KeyControl numpad5Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpad6Key
The 6 key on the numpad. The key in-between the numpad5Key to the let and
the numpad
Declaration
public KeyControl numpad6Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpad7Key
The 7 key on the numpad. The key on the left side of the numpad with numpad4Key
below it and num
Declaration
public KeyControl numpad7Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpad8Key
The 8 key on the numpad. The key in-between the numpad7Key to the left and the numpad9Key to the right.
Declaration
public KeyControl numpad8Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpad9Key
The 9 key on the numpad. The key in-between the numpad8Key to the left and
the numpad
Declaration
public KeyControl numpad9Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpadDivideKey
The divide ('/') key on the numpad. The key in-between numpad
Declaration
public KeyControl numpadDivideKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
PC keyboards usually have a 17-key numpad layout that differs from the 18-key layout
we use for reference. The 18-key layout is usually found on Mac keyboards. The numpad
divide key usually is the numpad
See Also
numpadEnterKey
The enter key on the numpad. The key sitting in the bottom right corner of the numpad.
Declaration
public KeyControl numpadEnterKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
numpadEqualsKey
The equals ('=') key on the numpad. The key in-between num
Declaration
public KeyControl numpadEqualsKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
PC keyboards usually have a 17-key numpad layout that differs from the 18-key layout we use for reference. The 18-key layout is usually found on Mac keyboards.
17-key numpad layouts do not usually have an equals key. On these PC keyboards, the equals key is usually the divide key.
See Also
numpadMinusKey
The minus ('-') key on the numpad. The key on the right side of the numpad with
numpad
Declaration
public KeyControl numpadMinusKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
PC keyboards usually have a 17-key numpad layout that differs from the 18-key layout
we use for reference. The 18-key layout is usually found on Mac keyboards. The numpad
minus key is usually not present on PC keyboards. Instead, the 17-key layout
has an elongated numpad
See Also
numpadMultiplyKey
The multiply ('*') key on the numpad. The key in the upper right corner of the numpad
with numpad
Declaration
public KeyControl numpadMultiplyKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
PC keyboards usually have a 17-key numpad layout that differs from the 18-key layout
we use for reference. The 18-key layout is usually found on Mac keyboards. The numpad
multiply key usually is the numpad
See Also
numpadPeriodKey
The period ('.') key on the numpad. The key in-between the numpad
Declaration
public KeyControl numpadPeriodKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
This key is the same in 17-key and 18-key numpad layouts.
See Also
numpadPlusKey
The plus ('+') key on the numpad. The key on the right side of the numpad with
numpad
Declaration
public KeyControl numpadPlusKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
PC keyboards usually have a 17-key numpad layout that differs from the 18-key layout we use for reference. The 18-key layout is usually found on Mac keyboards.
In particular, the plus key on the numpad is usually an elongated key that covers
the space of two keys. These 17-key numpads do not usually have a numpad
However, both on a 17-key and 18-key numpad, the plus key references the same physical key.
See Also
oKey
The 'o' key. The key in-between the i
Declaration
public KeyControl oKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
oem1Key
First additional key on the keyboard.
Declaration
public KeyControl oem1Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
Keyboards may have additional keys that are not part of the standardized 104-key keyboard layout
(105 in the case of an 18-key numpad). For example, many non-English keyboard layouts have an additional
key in-between left
Additional keys may be surfaced by the platform as "OEM" keys. There is no guarantee about where the keys are located and what symbols they produce. The OEM key controls are mainly there to surface the inputs but not with the intention of being used in standard bindings.
See Also
oem2Key
Second additional key on the keyboard.
Declaration
public KeyControl oem2Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
Keyboards may have additional keys that are not part of the standardized 104-key keyboard layout
(105 in the case of an 18-key numpad). For example, many non-English keyboard layouts have an additional
key in-between left
Additional keys may be surfaced by the platform as "OEM" keys. There is no guarantee about where the keys are located and what symbols they produce. The OEM key controls are mainly there to surface the inputs but not with the intention of being used in standard bindings.
See Also
oem3Key
Third additional key on the keyboard.
Declaration
public KeyControl oem3Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
Keyboards may have additional keys that are not part of the standardized 104-key keyboard layout
(105 in the case of an 18-key numpad). For example, many non-English keyboard layouts have an additional
key in-between left
Additional keys may be surfaced by the platform as "OEM" keys. There is no guarantee about where the keys are located and what symbols they produce. The OEM key controls are mainly there to surface the inputs but not with the intention of being used in standard bindings.
See Also
oem4Key
Fourth additional key on the keyboard.
Declaration
public KeyControl oem4Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
Keyboards may have additional keys that are not part of the standardized 104-key keyboard layout
(105 in the case of an 18-key numpad). For example, many non-English keyboard layouts have an additional
key in-between left
Additional keys may be surfaced by the platform as "OEM" keys. There is no guarantee about where the keys are located and what symbols they produce. The OEM key controls are mainly there to surface the inputs but not with the intention of being used in standard bindings.
See Also
oem5Key
Fifth additional key on the keyboard.
Declaration
public KeyControl oem5Key { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
Keyboards may have additional keys that are not part of the standardized 104-key keyboard layout
(105 in the case of an 18-key numpad). For example, many non-English keyboard layouts have an additional
key in-between left
Additional keys may be surfaced by the platform as "OEM" keys. There is no guarantee about where the keys are located and what symbols they produce. The OEM key controls are mainly there to surface the inputs but not with the intention of being used in standard bindings.
See Also
pKey
The 'p' key. The key in-between the o
Declaration
public KeyControl pKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
pageDownKey
Declaration
public KeyControl pageDownKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
pageUpKey
The page up key. Usually in a separate block with home
Declaration
public KeyControl pageUpKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
pauseKey
The pause/break key. The key sitting to the left of scroll
Declaration
public KeyControl pauseKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
periodKey
The '.' key. Second key to the left of right
Declaration
public KeyControl periodKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
printScreenKey
The Print Screen key. The key sitting in-between f12Key
to the left and scroll
Declaration
public KeyControl printScreenKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
qKey
The 'q' key. The key in-between the tab
Declaration
public KeyControl qKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
quoteKey
The ' key. The key immediately to the left of enter
Declaration
public KeyControl quoteKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
rKey
The 'r' key. The key in-between the e
Declaration
public KeyControl rKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
rightAltKey
The alt/option key on the right side of the keyboard.
Declaration
public KeyControl rightAltKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
rightAppleKey
Same as right
Declaration
public KeyControl rightAppleKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
rightArrowKey
The right arrow key. Usually in a block by itself and generally to the right
of down
Declaration
public KeyControl rightArrowKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
rightBracketKey
The ']' key. The key in-between left
Declaration
public KeyControl rightBracketKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
rightCommandKey
Same as right
Declaration
public KeyControl rightCommandKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
rightCtrlKey
The control/ctrl key on the right side of the keyboard.
Declaration
public KeyControl rightCtrlKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
This key is usually not present on Mac laptops.
Key
See Also
rightMetaKey
The system "meta" key (Windows key on PC, Apple/command key on Mac) on the right side of the keyboard.
Declaration
public KeyControl rightMetaKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
rightShiftKey
The shift key on the right side of the keyboard.
Declaration
public KeyControl rightShiftKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
rightWindowsKey
Same as right
Declaration
public KeyControl rightWindowsKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
sKey
The 's' key. The key in-between the a
Declaration
public KeyControl sKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
scrollLockKey
The Scroll Lock key. The key in-between the print
Declaration
public KeyControl scrollLockKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
semicolonKey
The ';' key. The key immediately to the left of quote
Declaration
public KeyControl semicolonKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
shiftKey
An artificial combination of left
Declaration
public ButtonControl shiftKey { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
Remarks
Button
This is a synthetic button which is considered pressed whenever the left and/or right shift key is pressed.
See Also
slashKey
The '/' key. The key immediately to the left of right
Declaration
public KeyControl slashKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
spaceKey
The space bar key at the bottom of the keyboard.
Declaration
public KeyControl spaceKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
tKey
The 't' key. The key in-between the r
Declaration
public KeyControl tKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
tabKey
The tab key, which is generally located on the left side above the caps
Declaration
public KeyControl tabKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
uKey
The 'u' key. The key in-between the y
Declaration
public KeyControl uKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
upArrowKey
The up arrow key. Usually in a block by itself and generally on top of the
down
Declaration
public KeyControl upArrowKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
vKey
The 'v' key. The key in-between the c
Declaration
public KeyControl vKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
wKey
The 'w' key. The key in-between the q
Declaration
public KeyControl wKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
xKey
The 'x' key. The key in-between the z
Declaration
public KeyControl xKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
yKey
The 'y' key. The key in-between the t
Declaration
public KeyControl yKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
zKey
The 'z' key. The key in-between the left
Declaration
public KeyControl zKey { get; }
Property Value
Type | Description |
---|---|
Key |
Remarks
Key
See Also
Methods
FindKeyOnCurrentKeyboardLayout(string)
Return the key control that, according to the currently active keyboard layout (see keyboard
Declaration
public KeyControl FindKeyOnCurrentKeyboardLayout(string displayName)
Parameters
Type | Name | Description |
---|---|---|
string | displayName | Display name reported for the key according to the currently active keyboard layout. |
Returns
Type | Description |
---|---|
Key |
The key control corresponding to the given text or |
Remarks
In most cases, this means that the key inputs the given text when pressed. However, this does not have to be the case. Keys do not necessarily lead to character input.
Examples
using UnityEngine;
using UnityEngine.InputSystem;
public class KeyboardUtils : MonoBehaviour
{
private void FindKey()
{
// Retrieve the q key on the current keyboard layout.
Keyboard.current.FindKeyOnCurrentKeyboardLayout("q");
}
}
See Also
FinishSetup()
Called after the keyboard has been constructed but before it is added to the system.
Declaration
protected override void FinishSetup()
Overrides
Remarks
This method can be overridden to perform control- or device-specific setup work. The most common use case is for looking up child controls and storing them in local getters.
Examples
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
public class MyKeyboard : Keyboard
{
public ButtonControl button { get; private set; }
protected override void FinishSetup()
{
// Cache controls in getters.
button = (ButtonControl)GetChildControl("button");
}
}
See Also
MakeCurrent()
Make this the current device of its type.
Declaration
public override void MakeCurrent()
Overrides
Remarks
This method is called automatically by the input system when a device is
added or when input is received on it. Many types of devices have .current
getters that allow querying the last used device of a specific type directly (for
example, see current).
There is one special case, however, related to noise. A device that has noisy controls
(i.e. controls for which noisy is true) may receive input events
that contain no meaningful user interaction but are simply just noise from the device. A
good example of this is the PS4 gamepad which has a built-in gyro and may thus constantly
feed events into the input system even if not being actually in use. If, for example, an
Xbox gamepad and PS4 gamepad are both connected to a PC and the user is playing with the
Xbox gamepad, the PS4 gamepad would still constantly make itself current
by simply flooding the system with events. Hence why by default, noise on .current
getters
will be filtered out and a device will only see MakeCurrent
getting called if their input
was detected on non-noisy controls.
Examples
using UnityEngine;
using UnityEngine.InputSystem;
public class InputExample : MonoBehaviour
{
void Start()
{
// Add a keyboard and make it the current keyboard.
var keyboard = InputSystem.AddDevice("Keyboard");
keyboard.MakeCurrent();
}
}
See Also
OnIMECompositionChanged(IMECompositionString)
This is called to set the IME composition strings. Fired once for every change containing the entire string.
Declaration
public void OnIMECompositionChanged(IMECompositionString compositionString)
Parameters
Type | Name | Description |
---|---|---|
IMEComposition |
compositionString | The IMEComposition |
Remarks
To call back to the changed composition string, subscribe to the on
Examples
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
public class KeyboardUtils : MonoBehaviour
{
private string compositionString = "";
void ChangeIMEComposition()
{
// Manually creating an input event to change the IME composition
var inputEvent = IMECompositionEvent.Create(Keyboard.current.deviceId, "CompositionTestCharacters! ɝ", Time.time);
Keyboard.current.OnIMECompositionChanged(inputEvent.compositionString);
}
}
See Also
OnRemoved()
Called by the system when the device is removed from devices.
Declaration
protected override void OnRemoved()
Overrides
Remarks
Examples
using UnityEngine.InputSystem;
public class MyDevice : InputDevice
{
public static MyDevice current { get; private set; }
protected override void OnRemoved()
{
// use this context to unassign the current device for instance
base.OnRemoved();
if (current == this)
current = null;
}
}
See Also
OnTextInput(char)
Called when text input on the keyboard is received.
Declaration
public void OnTextInput(char character)
Parameters
Type | Name | Description |
---|---|---|
char | character | A char type value that represents the character that has been entered. |
Remarks
The system will call this method automatically whenever a Text
Examples
using UnityEngine;
using UnityEngine.InputSystem;
public class OnTextInputExample : MonoBehaviour
{
// Simulate text input event on the current keyboard.
private void FakeInput()
{
Keyboard.current.OnTextInput('a');
}
}
See Also
RefreshConfiguration()
Refresh the configuration of the control. This is used to update the control's state (e.g. Keyboard Layout or display Name of Keys).
Declaration
protected override void RefreshConfiguration()
Overrides
Remarks
The system will call this method automatically whenever a change is made to one of the control's configuration properties.
This method is only relevant if you are implementing your own devices or new
types of controls which are fetching configuration data from the devices (such
as Key
Examples
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public class MyDevice : InputDevice
{
public enum Orientation
{
Horizontal,
Vertical,
}
private Orientation m_Orientation;
private static InternedString s_Vertical = new InternedString("Vertical");
private static InternedString s_Horizontal = new InternedString("Horizontal");
public Orientation orientation
{
get
{
// Call RefreshOrientation if the configuration of the device has been
// invalidated since last time we initialized m_Orientation.
// Calling RefreshConfigurationIfNeeded() is sufficient in most cases, RefreshConfiguration() forces the refresh.
RefreshConfiguration();
return m_Orientation;
}
}
protected override void RefreshConfiguration()
{
// Set Orientation back to horizontal. Alternatively fetch from device.
m_Orientation = Orientation.Horizontal;
// Reflect the orientation on the device.
switch (m_Orientation)
{
case Orientation.Vertical:
InputSystem.RemoveDeviceUsage(this, s_Horizontal);
InputSystem.AddDeviceUsage(this, s_Vertical);
break;
case Orientation.Horizontal:
InputSystem.RemoveDeviceUsage(this, s_Vertical);
InputSystem.AddDeviceUsage(this, s_Horizontal);
break;
}
}
}
See Also
SetIMECursorPosition(Vector2)
Sets the cursor position for IME composition dialogs. Units are from the upper left, in pixels, moving down and to the right.
Declaration
public void SetIMECursorPosition(Vector2 position)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | position | A Vector2 of the IME cursor position to set. |
Remarks
Some languages use complex input methods which involve opening windows to insert characters. Typically, this is not desirable while playing a game, as games may just interpret key strokes as game input, not as text.
See Set
Examples
using UnityEngine;
using UnityEngine.InputSystem;
public class KeyboardUtils : MonoBehaviour
{
private Vector2 cursorPosition;
void Update ()
{
// Set the IME cursor position to the mouse position
var x = Mouse.current.position.x.ReadValue();
var y = Mouse.current.position.y.ReadValue();
cursorPosition = new Vector2(x, y);
Keyboard.current.SetIMECursorPosition(cursorPosition);
}
}
See Also
SetIMEEnabled(bool)
Activates/deactivates IME composition while typing. This decides whether to use the OS supplied IME system or not.
Declaration
public void SetIMEEnabled(bool enabled)
Parameters
Type | Name | Description |
---|---|---|
bool | enabled | The IME composition enabled state. true to enable the IME, false to disable it. |
Remarks
Some languages use complex input methods which involve opening windows to insert characters. Typically, this is not desirable while playing a game, as games may just interpret key strokes as game input, not as text. Setting this to On, will enable the OS-level IME system when the user presses keystrokes.
See Set
Examples
using UnityEngine;
using UnityEngine.InputSystem;
public class KeyboardUtils : MonoBehaviour
{
private string compositionString = "";
void Start(){
Keyboard.current.SetIMEEnabled(true);
Keyboard.current.onIMECompositionChange += composition =>
{
compositionString = composition.ToString();
};
}
}
See Also
Events
onIMECompositionChange
When a user is entering text using IME composition, this event occurs each time the IME composition string changes, and provides the new composition string as a value. When using an IME, this event can be used to display the composition string while it is being edited.
Declaration
public event Action<IMECompositionString> onIMECompositionChange
Event Type
Type | Description |
---|---|
Action<IMEComposition |
Remarks
The composition string is held by the IMEComposition
Some languages use complex input methods which involve opening windows to insert characters. Typically, this is not desirable while playing a game, as games may just interpret key strokes as game input, not as text.
Many IMEs cause this event to fire with a blank string when the composition is submitted or reset, however it is best not to rely on this behaviour since it is IME dependent.
See Set
Examples
To subscribe to the onIMECompositionChange event, use the following sample code:
using UnityEngine;
using UnityEngine.InputSystem;
public class KeyboardUtils : MonoBehaviour
{
private string compositionString = "";
void Start(){
Keyboard.current.onIMECompositionChange += composition =>
{
compositionString = composition.ToString();
};
}
}
See Also
onTextInput
Event that is fired for every single character entered on the keyboard.
See On
Declaration
public event Action<char> onTextInput
Event Type
Examples
using System;
using UnityEngine;
using UnityEngine.InputSystem;
// Let's say we want to do a typing game. We could define a component
// something along those lines to match the typed input.
public class MatchTextByTyping : MonoBehaviour
{
public string text
{
get => m_Text;
set
{
m_Text = value;
m_Position = 0;
}
}
public Action onTextTypedCorrectly { get; set; }
public Action onTextTypedIncorrectly { get; set; }
private int m_Position;
private string m_Text;
protected void OnEnable()
{
Keyboard.current.onTextInput += OnTextInput;
}
protected void OnDisable()
{
Keyboard.current.onTextInput -= OnTextInput;
}
private void OnTextInput(char ch)
{
if (m_Text == null || m_Position >= m_Text.Length)
return;
if (m_Text[m_Position] == ch)
{
++m_Position;
if (m_Position == m_Text.Length)
onTextTypedCorrectly?.Invoke();
}
else
{
m_Text = null;
m_Position = 0;
onTextTypedIncorrectly?.Invoke();
}
}
}