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.
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 | Total number of key controls. |
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 is not valid. |
aKey
The 'a' key. The key immediately to the right of caps
Declaration
public KeyControl aKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the a key. |
allKeys
List of all key controls on the keyboard.
Declaration
public ReadOnlyArray<KeyControl> allKeys { get; }
Property Value
Type | Description |
---|---|
Read |
altKey
An artificial combination of left
Declaration
public ButtonControl altKey { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
Control representing a combined left and right alt key. |
Remarks
This is a synthetic button which is considered pressed whenever the left and/or right alt key is pressed.
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 |
Control representing the synthetic "anyKey". |
bKey
The 'b' key. The key in-between the v
Declaration
public KeyControl bKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the b key. |
backquoteKey
The ` key. The leftmost key in the row of digits. Directly above tab
Declaration
public KeyControl backquoteKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the backtick/quote key. |
backslashKey
The '' key. The key immediately to the right of right
Declaration
public KeyControl backslashKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the backslash key. |
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 |
Control representing the backspace key. |
Remarks
On the Mac, this key may be labeled "delete" which however is a
key different from delete
cKey
The 'c' key. The key in-between the x
Declaration
public KeyControl cKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the c key. |
capsLockKey
The Caps Lock key. The key below tab
Declaration
public KeyControl capsLockKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the caps lock key. |
commaKey
The ',' key. Third key to the left of right
Declaration
public KeyControl commaKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the comma key. |
contextMenuKey
The context menu key. This key is generally only found on PC keyboards. If present,
the key is found in-between the right
Declaration
public KeyControl contextMenuKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the context menu key. |
ctrlKey
An artificial combination of left
Declaration
public ButtonControl ctrlKey { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
Control representing a combined left and right ctrl key. |
Remarks
This is a synthetic button which is considered pressed whenever the left and/or right ctrl key is pressed.
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 |
dKey
The 'd' key. The key in-between the s
Declaration
public KeyControl dKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the d key. |
deleteKey
The 'delete' key. Usually in a separate block with end
Declaration
public KeyControl deleteKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the delete key. |
Remarks
On the Mac, the backspace
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 |
Control representing the 0 key. |
digit1Key
The '1' key. The key in-between the backquote
Declaration
public KeyControl digit1Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the 1 key. |
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 |
Control representing the 2 key. |
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 |
Control representing the 3 key. |
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 |
Control representing the 4 key. |
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 |
Control representing the 5 key. |
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 |
Control representing the 6 key. |
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 |
Control representing the 7 key. |
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 |
Control representing the 8 key. |
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 |
Control representing the 9 key. |
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 |
Control representing the down arrow key. |
eKey
The 'e' key. The key in-between the w
Declaration
public KeyControl eKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the e key. |
endKey
The 'end' key. Usually in a separate block with delete
Declaration
public KeyControl endKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the end key. |
enterKey
The enter/return key in the main key block.
Declaration
public KeyControl enterKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the enter key. |
Remarks
This key is distinct from the enter key on the numpad which is numpad
equalsKey
The '=' key in the main key block. The key in-between minus
Declaration
public KeyControl equalsKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the equals key. |
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 |
Control representing the escape key. |
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 |
Control representing the F10 key. |
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 |
Control representing the F11 key. |
f12Key
The F12 key. The key in-between f11Key to the left and print
Declaration
public KeyControl f12Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the F12 key. |
f1Key
The F1 key. The key in-between escape
Declaration
public KeyControl f1Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the F1 key. |
f2Key
Declaration
public KeyControl f2Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the F2 key. |
f3Key
Declaration
public KeyControl f3Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the F3 key. |
f4Key
Declaration
public KeyControl f4Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the F4 key. |
f5Key
Declaration
public KeyControl f5Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the F5 key. |
f6Key
Declaration
public KeyControl f6Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the F6 key. |
f7Key
Declaration
public KeyControl f7Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the F7 key. |
f8Key
Declaration
public KeyControl f8Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the F8 key. |
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 |
Control representing the F9 key. |
fKey
The 'f' key. The key in-between the d
Declaration
public KeyControl fKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the f key. |
gKey
The 'g' key. The key in-between the f
Declaration
public KeyControl gKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the g key. |
hKey
The 'h' key. The key in-between the g
Declaration
public KeyControl hKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the h key. |
homeKey
Declaration
public KeyControl homeKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the insert key. |
iKey
The 'i' key. The key in-between the u
Declaration
public KeyControl iKey { get; }
Property Value
Type | Description |
---|---|
Key |
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 key strokes as game input, not as text.
See Set
insertKey
The 'insert' key. Usually in a separate block with home
Declaration
public KeyControl insertKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the insert key. |
jKey
The 'j' key. The key in-between the h
Declaration
public KeyControl jKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the j key. |
kKey
The 'k' key. The key in-between the j
Declaration
public KeyControl kKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the k key. |
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
keys
Raw array of key controls on the keyboard.
Declaration
protected KeyControl[] keys { get; set; }
Property Value
Type | Description |
---|---|
Key |
lKey
The 'l' key. The key in-between the k
Declaration
public KeyControl lKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the l key. |
leftAltKey
The alt/option key on the left side of the keyboard.
Declaration
public KeyControl leftAltKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the left alt/option key. |
leftAppleKey
Same as left
Declaration
public KeyControl leftAppleKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the left Apple/command system key. |
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 |
Control representing the left arrow key. |
leftBracketKey
The '[' key. The key immediately to the left of right
Declaration
public KeyControl leftBracketKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the left bracket key. |
leftCommandKey
Same as left
Declaration
public KeyControl leftCommandKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the left Apple/command system key. |
leftCtrlKey
The control/ctrl key on the left side of the keyboard.
Declaration
public KeyControl leftCtrlKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the left control key. |
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 |
Control representing the left system meta key. |
leftShiftKey
The shift key on the left side of the keyboard.
Declaration
public KeyControl leftShiftKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the left shift key. |
leftWindowsKey
Same as left
Declaration
public KeyControl leftWindowsKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the left Windows system key. |
mKey
The 'm' key. The key in-between the n
Declaration
public KeyControl mKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the m key. |
minusKey
The '-' key. The second key to the left of backspace
Declaration
public KeyControl minusKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the minus key. |
nKey
The 'n' key. The key in-between the b
Declaration
public KeyControl nKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the n key. |
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 |
Control representing the num lock key. |
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 |
Control representing the numpad 0 key. |
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 |
Control representing the numpad 1 key. |
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 |
Control representing the numpad 2 key. |
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 |
Control representing the numpad 3 key. |
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 |
Control representing the numpad 4 key. |
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 |
Control representing the numpad 5 key. |
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 |
Control representing the numpad 6 key. |
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 |
Control representing the numpad 7 key. |
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 |
Control representing the numpad 8 key. |
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 |
Control representing the numpad 9 key. |
numpadDivideKey
The divide ('/') key on the numpad. The key in-between numpad
Declaration
public KeyControl numpadDivideKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the numpad divide key. |
Remarks
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
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 |
Control representing the numpad enter key. |
numpadEqualsKey
The equals ('=') key on the numpad. The key in-between num
Declaration
public KeyControl numpadEqualsKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the numpad equals key. |
Remarks
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.
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 |
Control representing the numpad minus key. |
Remarks
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
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 |
Control representing the numpad multiply key. |
Remarks
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
numpadPeriodKey
The period ('.') key on the numpad. The key in-between the numpad
Declaration
public KeyControl numpadPeriodKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the numpad period key. |
Remarks
This key is the same in 17-key and 18-key numpad layouts.
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 |
Control representing the numpad plus key. |
Remarks
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.
oKey
The 'o' key. The key in-between the i
Declaration
public KeyControl oKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the o key. |
oem1Key
First additional key on the keyboard.
Declaration
public KeyControl oem1Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing OEM1. |
Remarks
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.
oem2Key
Second additional key on the keyboard.
Declaration
public KeyControl oem2Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing OEM2. |
Remarks
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.
oem3Key
Third additional key on the keyboard.
Declaration
public KeyControl oem3Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing OEM3. |
Remarks
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.
oem4Key
Fourth additional key on the keyboard.
Declaration
public KeyControl oem4Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing OEM4. |
Remarks
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.
oem5Key
Fifth additional key on the keyboard.
Declaration
public KeyControl oem5Key { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing OEM5. |
Remarks
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.
pKey
The 'p' key. The key in-between the o
Declaration
public KeyControl pKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the p key. |
pageDownKey
Declaration
public KeyControl pageDownKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the page down key. |
pageUpKey
The page up key. Usually in a separate block with home
Declaration
public KeyControl pageUpKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the page up key. |
pauseKey
The pause/break key. The key sitting to the left of scroll
Declaration
public KeyControl pauseKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the pause/break key. |
periodKey
The '.' key. Second key to the left of right
Declaration
public KeyControl periodKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the period key. |
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 |
Control representing the print screen key. |
qKey
The 'q' key. The key in-between the tab
Declaration
public KeyControl qKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the q key. |
quoteKey
The ' key. The key immediately to the left of enter
Declaration
public KeyControl quoteKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the quote key. |
rKey
The 'r' key. The key in-between the e
Declaration
public KeyControl rKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the r key. |
rightAltKey
The alt/option key on the right side of the keyboard.
Declaration
public KeyControl rightAltKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the right alt/option key. |
rightAppleKey
Same as right
Declaration
public KeyControl rightAppleKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the right Apple/command system key. |
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 |
Control representing the right arrow key. |
rightBracketKey
The ']' key. The key in-between left
Declaration
public KeyControl rightBracketKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the right bracket key. |
rightCommandKey
Same as right
Declaration
public KeyControl rightCommandKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the right Apple/command system key. |
rightCtrlKey
The control/ctrl key on the right side of the keyboard.
Declaration
public KeyControl rightCtrlKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the right control key. |
Remarks
This key is usually not present on Mac laptops.
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 |
Control representing the right system meta key. |
rightShiftKey
The shift key on the right side of the keyboard.
Declaration
public KeyControl rightShiftKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the right shift key. |
rightWindowsKey
Same as right
Declaration
public KeyControl rightWindowsKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the right Windows system key. |
sKey
The 's' key. The key in-between the a
Declaration
public KeyControl sKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the s key. |
scrollLockKey
The Scroll Lock key. The key in-between the print
Declaration
public KeyControl scrollLockKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the scroll lock key. |
semicolonKey
The ';' key. The key immediately to the left of quote
Declaration
public KeyControl semicolonKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the semicolon key. |
shiftKey
An artificial combination of left
Declaration
public ButtonControl shiftKey { get; protected set; }
Property Value
Type | Description |
---|---|
Button |
Control representing a combined left and right shift key. |
Remarks
This is a synthetic button which is considered pressed whenever the left and/or right shift key is pressed.
slashKey
The '/' key. The key immediately to the left of right
Declaration
public KeyControl slashKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the forward slash key. |
spaceKey
The space bar key.
Declaration
public KeyControl spaceKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the space bar key. |
tKey
The 't' key. The key in-between the r
Declaration
public KeyControl tKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the t key. |
tabKey
The tab key.
Declaration
public KeyControl tabKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the tab key. |
uKey
The 'u' key. The key in-between the y
Declaration
public KeyControl uKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the u key. |
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 |
Control representing the up arrow key. |
vKey
The 'v' key. The key in-between the c
Declaration
public KeyControl vKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the v key. |
wKey
The 'w' key. The key in-between the q
Declaration
public KeyControl wKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the w key. |
xKey
The 'x' key. The key in-between the z
Declaration
public KeyControl xKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the x key. |
yKey
The 'y' key. The key in-between the t
Declaration
public KeyControl yKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the y key. |
zKey
The 'z' key. The key in-between the left
Declaration
public KeyControl zKey { get; }
Property Value
Type | Description |
---|---|
Key |
Control representing the z key. |
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.
See Also
FinishSetup()
Called after the keyboard has been constructed but before it is added to the system.
Declaration
protected override void FinishSetup()
Overrides
MakeCurrent()
Make the keyboard the current keyboard (i.e. current).
Declaration
public override void MakeCurrent()
Overrides
Remarks
A keyboard will automatically be made current when receiving input or when added to the input system.
OnIMECompositionChanged(IMECompositionString)
Called when an IME composition is in-progress or finished.
Declaration
public void OnIMECompositionChanged(IMECompositionString compositionString)
Parameters
Type | Name | Description |
---|---|---|
IMEComposition |
compositionString | The current composition. |
Remarks
The method will be repeatedly called with the current string while composition is in progress. Once composition finishes, the method will be called one more time with a blank composition string.
See Also
OnRemoved()
Called when the keyboard is removed from the system.
Declaration
protected override void OnRemoved()
Overrides
OnTextInput(char)
Called when text input on the keyboard is received.
Declaration
public void OnTextInput(char character)
Parameters
Type | Name | Description |
---|---|---|
char | character | Character that has been entered. |
Remarks
The system will call this automatically whenever a Text
RefreshConfiguration()
Declaration
protected override void RefreshConfiguration()
Overrides
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 |
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
SetIMEEnabled(bool)
Activates/deactivates IME composition while typing. This decides whether or not to use the OS supplied IME system.
Declaration
public void SetIMEEnabled(bool enabled)
Parameters
Type | Name | Description |
---|---|---|
bool | enabled |
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
Events
onIMECompositionChange
An event that is fired to get IME composition strings. Fired once for every change containing the entire string to date.
When using an IME, this event can be used to display the composition string while it is being edited. When a composition
string is submitted, one or many On
Declaration
public event Action<IMECompositionString> onIMECompositionChange
Event Type
Type | Description |
---|---|
Action<IMEComposition |
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.
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:
var compositionString = "";
Keyboard.current.onIMECompositionChange += composition =>
{
compositionString = composition.ToString();
};
onTextInput
Event that is fired for every single character entered on the keyboard.
Declaration
public event Action<char> onTextInput
Event Type
Remarks
// 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)
onTextTypeCorrectly?.Invoke();
}
else
{
m_Text = null;
m_Position = 0;
onTextTypedIncorrectly?.Invoke();
}
}
}