docs.unity.cn
    Show / Hide Table of Contents

    Class Keyboard

    Represents a standard, physical PC-type keyboard.

    Inheritance
    Object
    InputControl
    InputDevice
    Keyboard
    Inherited Members
    InputDevice.InvalidDeviceId
    InputDevice.description
    InputDevice.enabled
    InputDevice.canRunInBackground
    InputDevice.added
    InputDevice.remote
    InputDevice.native
    InputDevice.updateBeforeRender
    InputDevice.deviceId
    InputDevice.lastUpdateTime
    InputDevice.wasUpdatedThisFrame
    InputDevice.allControls
    InputDevice.valueType
    InputDevice.valueSizeInBytes
    InputDevice.all
    InputDevice.ReadValueFromBufferAsObject(Void*, Int32)
    InputDevice.ReadValueFromStateAsObject(Void*)
    InputDevice.ReadValueFromStateIntoBuffer(Void*, Void*, Int32)
    InputDevice.CompareValue(Void*, Void*)
    InputDevice.OnAdded()
    InputDevice.OnConfigurationChanged()
    InputDevice.ExecuteCommand<TCommand>(TCommand)
    InputDevice.ExecuteCommand(InputDeviceCommand*)
    InputControl.name
    InputControl.displayName
    InputControl.shortDisplayName
    InputControl.path
    InputControl.layout
    InputControl.variants
    InputControl.device
    InputControl.parent
    InputControl.children
    InputControl.usages
    InputControl.aliases
    InputControl.stateBlock
    InputControl.noisy
    InputControl.synthetic
    InputControl.Item[String]
    InputControl.ToString()
    InputControl.EvaluateMagnitude()
    InputControl.EvaluateMagnitude(Void*)
    InputControl.WriteValueFromBufferIntoState(Void*, Int32, Void*)
    InputControl.WriteValueFromObjectIntoState(Object, Void*)
    InputControl.TryGetChildControl(String)
    InputControl.TryGetChildControl<TControl>(String)
    InputControl.GetChildControl(String)
    InputControl.GetChildControl<TControl>(String)
    InputControl.RefreshConfigurationIfNeeded()
    InputControl.m_StateBlock
    InputControl.currentStatePtr
    InputControl.previousFrameStatePtr
    InputControl.defaultStatePtr
    InputControl.noiseMaskPtr
    InputControl.stateOffsetRelativeToDeviceRoot
    Namespace: UnityEngine.InputSystem
    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 KeyControl-type controls present on the keyboard. For example, aKey. To receive text input, use the onTextInput callback.

    The naming/identification of keys is agnostic to keyboard layouts. This means that aKey, for example, will always be the key to the right of capsLockKey regardless of where the current keyboard language layout puts the "a" character. This also means that having a binding to "<Keyboard>/a" on an InputAction, for example, will bind to the same key regardless of locale -- an important feature, for example, for getting stable WASD bindings.

    To find what text character (if any) is produced by a key, you can use the key's displayName property. This can also be used in bindings. "<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 keyboardLayout property. Note that keyboard layout names are platform-dependent.

    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 allKeys.

    Declaration
    public const int KeyCount = null
    Field Value
    Type Description
    Int32

    Total number of key controls.

    Properties

    aKey

    The 'a' key. The key immediately to the right of capsLockKey.

    Declaration
    public KeyControl aKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the a key.

    allKeys

    List of all key controls on the keyboard.

    Declaration
    public ReadOnlyArray<KeyControl> allKeys { get; }
    Property Value
    Type Description
    ReadOnlyArray<KeyControl>

    altKey

    An artificial combination of leftAltKey and rightAltKey into one control.

    Declaration
    public ButtonControl altKey { get; protected set; }
    Property Value
    Type Description
    ButtonControl

    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
    AnyKeyControl

    Control representing the synthetic "anyKey".

    backquoteKey

    The ` key. The leftmost key in the row of digits. Directly above tabKey.

    Declaration
    public KeyControl backquoteKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the backtick/quote key.

    backslashKey

    The '&apos; key. The key immediately to the right of rightBracketKey and next to or above enterKey.

    Declaration
    public KeyControl backslashKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the backslash key.

    backspaceKey

    The backspace key (usually labeled "delete" on Mac). The rightmost key in the top digit row with equalsKey to the left.

    Declaration
    public KeyControl backspaceKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the backspace key.

    Remarks

    On the Mac, this key may be labeled "delete" which however is a key different from deleteKey.

    bKey

    The 'b' key. The key in-between the vKey to the left and the nKey to the right in the bottom-most row of alphabetic characters.

    Declaration
    public KeyControl bKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the b key.

    capsLockKey

    The Caps Lock key. The key below tabKey and above leftShiftKey.

    Declaration
    public KeyControl capsLockKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the caps lock key.

    cKey

    The 'c' key. The key in-between the xKey to the left and the vKey to the right in the bottom-most row of alphabetic characters.

    Declaration
    public KeyControl cKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the c key.

    commaKey

    The ',' key. Third key to the left of rightShiftKey.

    Declaration
    public KeyControl commaKey { get; }
    Property Value
    Type Description
    KeyControl

    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 rightWindowsKey to the left and the rightCtrlKey to the right. It's intention is to bring up the context menu according to the current selection.

    Declaration
    public KeyControl contextMenuKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the context menu key.

    ctrlKey

    An artificial combination of leftCtrlKey and rightCtrlKey into one control.

    Declaration
    public ButtonControl ctrlKey { get; protected set; }
    Property Value
    Type Description
    ButtonControl

    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

    deleteKey

    The 'delete' key. Usually in a separate block with endKey to its right and insertKey sitting above it.

    Declaration
    public KeyControl deleteKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the delete key.

    Remarks

    On the Mac, the backspaceKey is also labeled "delete". However, this is not this key.

    digit0Key

    The '0' key. The key in-between the digit9Key to the left and the minusKey to the right in the row of digit characters.

    Declaration
    public KeyControl digit0Key { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the 0 key.

    digit1Key

    The '1' key. The key in-between the backquoteKey to the left and the digit2Key to the right in the row of digit characters.

    Declaration
    public KeyControl digit1Key { get; }
    Property Value
    Type Description
    KeyControl

    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
    KeyControl

    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
    KeyControl

    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
    KeyControl

    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
    KeyControl

    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
    KeyControl

    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
    KeyControl

    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
    KeyControl

    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
    KeyControl

    Control representing the 9 key.

    dKey

    The 'd' key. The key in-between the sKey to the left and the fKey to the right in the middle row of alphabetic characters.

    Declaration
    public KeyControl dKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the d key.

    downArrowKey

    The down arrow key. Usually in a block by itself and generally below the upArrowKey and in-between leftArrowKey to the left and rightArrowKey to the right.

    Declaration
    public KeyControl downArrowKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the down arrow key.

    eKey

    The 'e' key. The key in-between the wKey to the left and the rKey to the right in the topmost row of alphabetic characters.

    Declaration
    public KeyControl eKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the e key.

    endKey

    The 'end' key. Usually in a separate block with deleteKey to the left and pageDownKey to the right.

    Declaration
    public KeyControl endKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the end key.

    enterKey

    The enter/return key in the main key block.

    Declaration
    public KeyControl enterKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the enter key.

    Remarks

    This key is distinct from the enter key on the numpad which is numpadEnterKey.

    equalsKey

    The '=' key in the main key block. The key in-between minusKey to the left and backspaceKey to the right.

    Declaration
    public KeyControl equalsKey { get; }
    Property Value
    Type Description
    KeyControl

    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
    KeyControl

    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
    KeyControl

    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
    KeyControl

    Control representing the F11 key.

    f12Key

    The F12 key. The key in-between f11Key to the left and printScreenKey to the right in the topmost row of keys.

    Declaration
    public KeyControl f12Key { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the F12 key.

    f1Key

    The F1 key. The key in-between escapeKey to the left and f1Key to the right in the topmost row of keys.

    Declaration
    public KeyControl f1Key { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the F1 key.

    f2Key

    The F2 key. The key in-between f1Key to the left and f3Key to the right in the topmost row of keys.

    Declaration
    public KeyControl f2Key { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the F2 key.

    f3Key

    The F3 key. The key in-between f2Key to the left and f4Key to the right in the topmost row of keys.

    Declaration
    public KeyControl f3Key { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the F3 key.

    f4Key

    The F4 key. The key in-between f3Key to the left and f5Key to the right in the topmost row of keys.

    Declaration
    public KeyControl f4Key { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the F4 key.

    f5Key

    The F5 key. The key in-between f4Key to the left and f6Key to the right in the topmost row of keys.

    Declaration
    public KeyControl f5Key { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the F5 key.

    f6Key

    The F6 key. The key in-between f5Key to the left and f7Key to the right in the topmost row of keys.

    Declaration
    public KeyControl f6Key { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the F6 key.

    f7Key

    The F7 key. The key in-between f6Key to the left and f8Key to the right in the topmost row of keys.

    Declaration
    public KeyControl f7Key { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the F7 key.

    f8Key

    The F8 key. The key in-between f7Key to the left and f9Key to the right in the topmost row of keys.

    Declaration
    public KeyControl f8Key { get; }
    Property Value
    Type Description
    KeyControl

    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
    KeyControl

    Control representing the F9 key.

    fKey

    The 'f' key. The key in-between the dKey to the left and the gKey to the right in the middle row of alphabetic characters.

    Declaration
    public KeyControl fKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the f key.

    gKey

    The 'g' key. The key in-between the fKey to the left and the hKey to the right in the middle row of alphabetic characters.

    Declaration
    public KeyControl gKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the g key.

    hKey

    The 'h' key. The key in-between the gKey to the left and the jKey to the right in the middle row of alphabetic characters.

    Declaration
    public KeyControl hKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the h key.

    homeKey

    The 'home' key. Usually in a separate block with pageUpKey to the right and insertKey to the left.

    Declaration
    public KeyControl homeKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the insert key.

    iKey

    The 'i' key. The key in-between the uKey to the left and the oKey to the right in the top row of alphabetic characters.

    Declaration
    public KeyControl iKey { get; }
    Property Value
    Type Description
    KeyControl

    imeSelected

    True when IME composition is enabled. Requires SetIMEEnabled(Boolean) to be called to enable IME, and the user to enable it at the OS level.

    Declaration
    public ButtonControl imeSelected { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    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 SetIMEEnabled(Boolean) for turning IME on/off

    insertKey

    The 'insert' key. Usually in a separate block with homeKey to its right and deleteKey sitting below it.

    Declaration
    public KeyControl insertKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the insert key.

    Item[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
    KeyControl
    Remarks

    This is equivalent to allKeys[(int)key - 1].

    jKey

    The 'j' key. The key in-between the hKey to the left and the kKey to the right in the middle row of alphabetic characters.

    Declaration
    public KeyControl jKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the j 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 displayName.

    keys

    Raw array of key controls on the keyboard.

    Declaration
    protected KeyControl[] keys { get; set; }
    Property Value
    Type Description
    KeyControl[]

    kKey

    The 'k' key. The key in-between the jKey to the left and the lKey to the right in the middle row of alphabetic characters.

    Declaration
    public KeyControl kKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the k key.

    leftAltKey

    The alt/option key on the left side of the keyboard.

    Declaration
    public KeyControl leftAltKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the left alt/option key.

    leftAppleKey

    Same as leftMetaKey. Apple/command system key on left side of keyboard.

    Declaration
    public KeyControl leftAppleKey { get; }
    Property Value
    Type Description
    KeyControl

    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 downArrowKey.

    Declaration
    public KeyControl leftArrowKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the left arrow key.

    leftBracketKey

    The '[' key. The key immediately to the left of rightBracketKey.

    Declaration
    public KeyControl leftBracketKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the left bracket key.

    leftCommandKey

    Same as leftMetaKey. Apple/command system key on left side of keyboard.

    Declaration
    public KeyControl leftCommandKey { get; }
    Property Value
    Type Description
    KeyControl

    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
    KeyControl

    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
    KeyControl

    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
    KeyControl

    Control representing the left shift key.

    leftWindowsKey

    Same as leftMetaKey. Windows system key on left side of keyboard.

    Declaration
    public KeyControl leftWindowsKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the left Windows system key.

    lKey

    The 'l' key. The key in-between the kKey to the left and the semicolonKey to the right in the middle row of alphabetic characters.

    Declaration
    public KeyControl lKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the l key.

    minusKey

    The '-' key. The second key to the left of backspaceKey.

    Declaration
    public KeyControl minusKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the minus key.

    mKey

    The 'm' key. The key in-between the nKey to the left and the commaKey to the right in the bottom row of alphabetic characters.

    Declaration
    public KeyControl mKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the m key.

    nKey

    The 'n' key. The key in-between the bKey to the left and the mKey to the right in the bottom row of alphabetic characters.

    Declaration
    public KeyControl nKey { get; }
    Property Value
    Type Description
    KeyControl

    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
    KeyControl

    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
    KeyControl

    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
    KeyControl

    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
    KeyControl

    Control representing the numpad 2 key.

    numpad3Key

    The 3 key on the numpad. The key with the numpad2Key to its left and the numpadEnterKey to its right.

    Declaration
    public KeyControl numpad3Key { get; }
    Property Value
    Type Description
    KeyControl

    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
    KeyControl

    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
    KeyControl

    Control representing the numpad 5 key.

    numpad6Key

    The 6 key on the numpad. The key in-between the numpad5Key to the let and the numpadPlusKey to the right.

    Declaration
    public KeyControl numpad6Key { get; }
    Property Value
    Type Description
    KeyControl

    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 numLockKey above it.

    Declaration
    public KeyControl numpad7Key { get; }
    Property Value
    Type Description
    KeyControl

    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
    KeyControl

    Control representing the numpad 8 key.

    numpad9Key

    The 9 key on the numpad. The key in-between the numpad8Key to the left and the numpadMinusKey to the right (or, on 17-key PC keyboard numpads, the elongated plus key).

    Declaration
    public KeyControl numpad9Key { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the numpad 9 key.

    numpadDivideKey

    The divide ('/') key on the numpad. The key in-between numpadEqualsKey to the left and numpadMultiplyKey to the right.

    Declaration
    public KeyControl numpadDivideKey { get; }
    Property Value
    Type Description
    KeyControl

    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 numpadEqualsKey on PC keyboards.

    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
    KeyControl

    Control representing the numpad enter key.

    numpadEqualsKey

    The equals ('=') key on the numpad. The key in-between numLockKey to the left and numpadDivideKey to the right in the top row of the numpad.

    Declaration
    public KeyControl numpadEqualsKey { get; }
    Property Value
    Type Description
    KeyControl

    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 numpadMultiplyKey above it and numpadPlusKey below it.

    Declaration
    public KeyControl numpadMinusKey { get; }
    Property Value
    Type Description
    KeyControl

    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 numpadPlusKey that covers the space of two keys.

    numpadMultiplyKey

    The multiply ('*') key on the numpad. The key in the upper right corner of the numpad with numpadDivideKey to the left and numpadMultiplyKey below it.

    Declaration
    public KeyControl numpadMultiplyKey { get; }
    Property Value
    Type Description
    KeyControl

    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 numpadMinusKey on PC keyboards.

    numpadPeriodKey

    The period ('.') key on the numpad. The key in-between the numpadEnterKey to the right and the numpad0Key to the left.

    Declaration
    public KeyControl numpadPeriodKey { get; }
    Property Value
    Type Description
    KeyControl

    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 numpadMinusKey above it and numpadEnterKey below it.

    Declaration
    public KeyControl numpadPlusKey { get; }
    Property Value
    Type Description
    KeyControl

    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 numpadEqualsKey and the key above the plus key will usually be the numpad minus key.

    However, both on a 17-key and 18-key numpad, the plus key references the same physical key.

    oem1Key

    First additional key on the keyboard.

    Declaration
    public KeyControl oem1Key { get; }
    Property Value
    Type Description
    KeyControl

    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 leftShiftKey and zKey.

    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
    KeyControl

    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 leftShiftKey and zKey.

    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
    KeyControl

    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 leftShiftKey and zKey.

    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
    KeyControl

    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 leftShiftKey and zKey.

    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
    KeyControl

    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 leftShiftKey and zKey.

    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.

    oKey

    The 'o' key. The key in-between the iKey to the left and the pKey to the right in the top row of alphabetic characters.

    Declaration
    public KeyControl oKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the o key.

    pageDownKey

    The page down key. Usually in a separate block with endKey to the left and pageUpKey above it.

    Declaration
    public KeyControl pageDownKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the page down key.

    pageUpKey

    The page up key. Usually in a separate block with homeKey to the left and pageDownKey below it.

    Declaration
    public KeyControl pageUpKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the page up key.

    pauseKey

    The pause/break key. The key sitting to the left of scrollLockKey. May also be labeled "F15".

    Declaration
    public KeyControl pauseKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the pause/break key.

    periodKey

    The '.' key. Second key to the left of rightShiftKey.

    Declaration
    public KeyControl periodKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the period key.

    pKey

    The 'p' key. The key in-between the oKey to the left and the leftBracketKey to the right in the top row of alphabetic characters.

    Declaration
    public KeyControl pKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the p key.

    printScreenKey

    The Print Screen key. The key sitting in-between f12Key to the left and scrollLockKey to the right. May also be labeled "F13".

    Declaration
    public KeyControl printScreenKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the print screen key.

    qKey

    The 'q' key. The key in-between the tabKey to the left and the wKey to the right in the top row of alphabetic characters.

    Declaration
    public KeyControl qKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the q key.

    quoteKey

    The ' key. The key immediately to the left of enterKey.

    Declaration
    public KeyControl quoteKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the quote key.

    rightAltKey

    The alt/option key on the right side of the keyboard.

    Declaration
    public KeyControl rightAltKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the right alt/option key.

    rightAppleKey

    Same as rightMetaKey. Apple/command system key on right side of keyboard.

    Declaration
    public KeyControl rightAppleKey { get; }
    Property Value
    Type Description
    KeyControl

    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 downArrowKey

    Declaration
    public KeyControl rightArrowKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the right arrow key.

    rightBracketKey

    The ']' key. The key in-between leftBracketKey to the left and backslashKey to the right.

    Declaration
    public KeyControl rightBracketKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the right bracket key.

    rightCommandKey

    Same as rightMetaKey. Apple/command system key on right side of keyboard.

    Declaration
    public KeyControl rightCommandKey { get; }
    Property Value
    Type Description
    KeyControl

    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
    KeyControl

    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
    KeyControl

    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
    KeyControl

    Control representing the right shift key.

    rightWindowsKey

    Same as rightMetaKey. Windows system key on right side of keyboard.

    Declaration
    public KeyControl rightWindowsKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the right Windows system key.

    rKey

    The 'r' key. The key in-between the eKey to the left and the tKey to the right in the top row of alphabetic characters.

    Declaration
    public KeyControl rKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the r key.

    scrollLockKey

    The Scroll Lock key. The key in-between the printScreenKey to the left and the pauseKey to the right. May also be labeled "F14".

    Declaration
    public KeyControl scrollLockKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the scroll lock key.

    semicolonKey

    The ';' key. The key immediately to the left of quoteKey.

    Declaration
    public KeyControl semicolonKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the semicolon key.

    shiftKey

    An artificial combination of leftShiftKey and rightShiftKey into one control.

    Declaration
    public ButtonControl shiftKey { get; protected set; }
    Property Value
    Type Description
    ButtonControl

    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.

    sKey

    The 's' key. The key in-between the aKey to the left and the dKey to the right in the middle row of alphabetic characters.

    Declaration
    public KeyControl sKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the s key.

    slashKey

    The '/' key. The key immediately to the left of rightShiftKey.

    Declaration
    public KeyControl slashKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the forward slash key.

    spaceKey

    The space bar key.

    Declaration
    public KeyControl spaceKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the space bar key.

    tabKey

    The tab key.

    Declaration
    public KeyControl tabKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the tab key.

    tKey

    The 't' key. The key in-between the rKey to the left and the yKey to the right in the top row of alphabetic characters.

    Declaration
    public KeyControl tKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the t key.

    uKey

    The 'u' key. The key in-between the yKey to the left and the iKey to the right in the top row of alphabetic characters.

    Declaration
    public KeyControl uKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the u key.

    upArrowKey

    The up arrow key. Usually in a block by itself and generally on top of the downArrowKey.

    Declaration
    public KeyControl upArrowKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the up arrow key.

    vKey

    The 'v' key. The key in-between the cKey to the left and the bKey to the right in the bottom row of alphabetic characters.

    Declaration
    public KeyControl vKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the v key.

    wKey

    The 'w' key. The key in-between the qKey to the left and the eKey to the right in the top row of alphabetic characters.

    Declaration
    public KeyControl wKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the w key.

    xKey

    The 'x' key. The key in-between the zKey to the left and the cKey to the right in the bottom row of alphabetic characters.

    Declaration
    public KeyControl xKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the x key.

    yKey

    The 'y' key. The key in-between the tKey to the left and the uKey to the right in the top row of alphabetic characters.

    Declaration
    public KeyControl yKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the y key.

    zKey

    The 'z' key. The key in-between the leftShiftKey to the left and the xKey to the right in the bottom row of alphabetic characters.

    Declaration
    public KeyControl zKey { get; }
    Property Value
    Type Description
    KeyControl

    Control representing the z key.

    Methods

    FindKeyOnCurrentKeyboardLayout(String)

    Return the key control that, according to the currently active keyboard layout (see keyboardLayout), is associated with the given text.

    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
    KeyControl

    The key control corresponding to the given text or null if no such key was found on the current keyboard layout.

    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.

    // Find key that prints 'q' character (if any). Keyboard.current.FindKeyOnCurrentKeyboardLayout("q");
    See Also
    keyboardLayout

    FinishSetup()

    Called after the keyboard has been constructed but before it is added to the system.

    Declaration
    protected override void FinishSetup()
    Overrides
    InputControl.FinishSetup()

    MakeCurrent()

    Make the keyboard the current keyboard (i.e. current).

    Declaration
    public override void MakeCurrent()
    Overrides
    InputDevice.MakeCurrent()
    Remarks

    A keyboard will automatically be made current when receiving input or when added to the input system.

    OnIMECompositionChanged(IMECompositionString)

    Declaration
    public void OnIMECompositionChanged(IMECompositionString compositionString)
    Parameters
    Type Name Description
    IMECompositionString compositionString
    Implements
    ITextInputReceiver.OnIMECompositionChanged(IMECompositionString)

    OnRemoved()

    Called when the keyboard is removed from the system.

    Declaration
    protected override void OnRemoved()
    Overrides
    InputDevice.OnRemoved()

    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.

    Implements
    ITextInputReceiver.OnTextInput(Char)
    Remarks

    The system will call this automatically whenever a TextEvent is received that targets the keyboard device.

    RefreshConfiguration()

    Declaration
    protected override void RefreshConfiguration()
    Overrides
    InputControl.RefreshConfiguration()

    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 SetIMEEnabled(Boolean) for turning IME on/off

    SetIMEEnabled(Boolean)

    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
    Boolean 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 SetIMECursorPosition(Vector2), onIMECompositionChange, imeSelected for more IME settings and data.

    Events

    onIMECompositionChange

    An event that is fired to get IME composition strings. Fired once for every change, sends the entire string to date, and sends a blank string whenever a composition is submitted or reset.

    Declaration
    public event Action<IMECompositionString> onIMECompositionChange
    Event Type
    Type Description
    Action<IMECompositionString>
    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 SetIMEEnabled(Boolean) for turning IME on/off

    onTextInput

    Event that is fired for every single character entered on the keyboard.

    Declaration
    public event Action<char> onTextInput
    Event Type
    Type Description
    Action<Char>

    Triggered whenever the keyboard receives text input.

    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();
            }
        }
    }

    Extension Methods

    InputControlExtensions.FindInParentChain<TControl>(InputControl)
    InputControlExtensions.IsPressed(InputControl, Single)
    InputControlExtensions.IsActuated(InputControl, Single)
    InputControlExtensions.ReadValueAsObject(InputControl)
    InputControlExtensions.ReadValueIntoBuffer(InputControl, Void*, Int32)
    InputControlExtensions.ReadDefaultValueAsObject(InputControl)
    InputControlExtensions.ReadValueFromEventAsObject(InputControl, InputEventPtr)
    InputControlExtensions.WriteValueFromObjectIntoEvent(InputControl, InputEventPtr, Object)
    InputControlExtensions.WriteValueIntoState(InputControl, Void*)
    InputControlExtensions.WriteValueIntoState<TValue>(InputControl, TValue, Void*)
    InputControlExtensions.WriteValueIntoEvent<TValue>(InputControl, TValue, InputEventPtr)
    InputControlExtensions.CopyState(InputDevice, Void*, Int32)
    InputControlExtensions.CopyState<TState>(InputDevice, out TState)
    InputControlExtensions.CheckStateIsAtDefault(InputControl)
    InputControlExtensions.CheckStateIsAtDefault(InputControl, Void*, Void*)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl, Void*)
    InputControlExtensions.CompareStateIgnoringNoise(InputControl, Void*)
    InputControlExtensions.CompareState(InputControl, Void*, Void*, Void*)
    InputControlExtensions.CompareState(InputControl, Void*, Void*)
    InputControlExtensions.HasValueChangeInState(InputControl, Void*)
    InputControlExtensions.HasValueChangeInEvent(InputControl, InputEventPtr)
    InputControlExtensions.GetStatePtrFromStateEvent(InputControl, InputEventPtr)
    InputControlExtensions.ResetToDefaultStateInEvent(InputControl, InputEventPtr)
    InputControlExtensions.FindControlsRecursive<TControl>(InputControl, IList<TControl>, Func<TControl, Boolean>)
    Back to top Copyright © 2022 Unity Technologies
    Generated by DocFX
    on Wednesday, January 5, 2022
    Terms of use