using System;
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.InputSystem.Layouts;
////FIXME: display names for keys should be localized key names, not just printable characters (e.g. "Space" should be called "Leertaste")
////TODO: usages on modifiers so they can be identified regardless of platform conventions
namespace UnityEngine.InputSystem.LowLevel
{
///
/// Default state layout for keyboards.
///
///
/// Can be used to update the state of devices.
///
///
///
/// // Send input event with A key pressed on keyboard.
/// InputSystem.QueueStateEvent(Keyboard.current,
/// new KeyboardState(Key.A));
///
///
///
///
// NOTE: This layout has to match the KeyboardInputState layout used in native!
[StructLayout(LayoutKind.Sequential)]
public unsafe struct KeyboardState : IInputStateTypeInfo
{
///
/// Memory format tag for KeybboardState.
///
/// Returns "KEYS".
///
public static FourCC Format => new FourCC('K', 'E', 'Y', 'S');
private const int kSizeInBits = Keyboard.KeyCount;
internal const int kSizeInBytes = (kSizeInBits + 7) / 8;
[InputControl(name = "anyKey", displayName = "Any Key", layout = "AnyKey", sizeInBits = kSizeInBits - 1, synthetic = true)] // Exclude IMESelected.
[InputControl(name = "escape", displayName = "Escape", layout = "Key", usages = new[] {"Back", "Cancel"}, bit = (int)Key.Escape)]
[InputControl(name = "space", displayName = "Space", layout = "Key", bit = (int)Key.Space)]
[InputControl(name = "enter", displayName = "Enter", layout = "Key", usage = "Submit", bit = (int)Key.Enter)]
[InputControl(name = "tab", displayName = "Tab", layout = "Key", bit = (int)Key.Tab)]
[InputControl(name = "backquote", displayName = "`", layout = "Key", bit = (int)Key.Backquote)]
[InputControl(name = "quote", displayName = "'", layout = "Key", bit = (int)Key.Quote)]
[InputControl(name = "semicolon", displayName = ";", layout = "Key", bit = (int)Key.Semicolon)]
[InputControl(name = "comma", displayName = ",", layout = "Key", bit = (int)Key.Comma)]
[InputControl(name = "period", displayName = ".", layout = "Key", bit = (int)Key.Period)]
[InputControl(name = "slash", displayName = "/", layout = "Key", bit = (int)Key.Slash)]
[InputControl(name = "backslash", displayName = "\\", layout = "Key", bit = (int)Key.Backslash)]
[InputControl(name = "leftBracket", displayName = "[", layout = "Key", bit = (int)Key.LeftBracket)]
[InputControl(name = "rightBracket", displayName = "]", layout = "Key", bit = (int)Key.RightBracket)]
[InputControl(name = "minus", displayName = "-", layout = "Key", bit = (int)Key.Minus)]
[InputControl(name = "equals", displayName = "=", layout = "Key", bit = (int)Key.Equals)]
[InputControl(name = "upArrow", displayName = "Up Arrow", layout = "Key", bit = (int)Key.UpArrow)]
[InputControl(name = "downArrow", displayName = "Down Arrow", layout = "Key", bit = (int)Key.DownArrow)]
[InputControl(name = "leftArrow", displayName = "Left Arrow", layout = "Key", bit = (int)Key.LeftArrow)]
[InputControl(name = "rightArrow", displayName = "Right Arrow", layout = "Key", bit = (int)Key.RightArrow)]
[InputControl(name = "a", displayName = "A", layout = "Key", bit = (int)Key.A)]
[InputControl(name = "b", displayName = "B", layout = "Key", bit = (int)Key.B)]
[InputControl(name = "c", displayName = "C", layout = "Key", bit = (int)Key.C)]
[InputControl(name = "d", displayName = "D", layout = "Key", bit = (int)Key.D)]
[InputControl(name = "e", displayName = "E", layout = "Key", bit = (int)Key.E)]
[InputControl(name = "f", displayName = "F", layout = "Key", bit = (int)Key.F)]
[InputControl(name = "g", displayName = "G", layout = "Key", bit = (int)Key.G)]
[InputControl(name = "h", displayName = "H", layout = "Key", bit = (int)Key.H)]
[InputControl(name = "i", displayName = "I", layout = "Key", bit = (int)Key.I)]
[InputControl(name = "j", displayName = "J", layout = "Key", bit = (int)Key.J)]
[InputControl(name = "k", displayName = "K", layout = "Key", bit = (int)Key.K)]
[InputControl(name = "l", displayName = "L", layout = "Key", bit = (int)Key.L)]
[InputControl(name = "m", displayName = "M", layout = "Key", bit = (int)Key.M)]
[InputControl(name = "n", displayName = "N", layout = "Key", bit = (int)Key.N)]
[InputControl(name = "o", displayName = "O", layout = "Key", bit = (int)Key.O)]
[InputControl(name = "p", displayName = "P", layout = "Key", bit = (int)Key.P)]
[InputControl(name = "q", displayName = "Q", layout = "Key", bit = (int)Key.Q)]
[InputControl(name = "r", displayName = "R", layout = "Key", bit = (int)Key.R)]
[InputControl(name = "s", displayName = "S", layout = "Key", bit = (int)Key.S)]
[InputControl(name = "t", displayName = "T", layout = "Key", bit = (int)Key.T)]
[InputControl(name = "u", displayName = "U", layout = "Key", bit = (int)Key.U)]
[InputControl(name = "v", displayName = "V", layout = "Key", bit = (int)Key.V)]
[InputControl(name = "w", displayName = "W", layout = "Key", bit = (int)Key.W)]
[InputControl(name = "x", displayName = "X", layout = "Key", bit = (int)Key.X)]
[InputControl(name = "y", displayName = "Y", layout = "Key", bit = (int)Key.Y)]
[InputControl(name = "z", displayName = "Z", layout = "Key", bit = (int)Key.Z)]
[InputControl(name = "1", displayName = "1", layout = "Key", bit = (int)Key.Digit1)]
[InputControl(name = "2", displayName = "2", layout = "Key", bit = (int)Key.Digit2)]
[InputControl(name = "3", displayName = "3", layout = "Key", bit = (int)Key.Digit3)]
[InputControl(name = "4", displayName = "4", layout = "Key", bit = (int)Key.Digit4)]
[InputControl(name = "5", displayName = "5", layout = "Key", bit = (int)Key.Digit5)]
[InputControl(name = "6", displayName = "6", layout = "Key", bit = (int)Key.Digit6)]
[InputControl(name = "7", displayName = "7", layout = "Key", bit = (int)Key.Digit7)]
[InputControl(name = "8", displayName = "8", layout = "Key", bit = (int)Key.Digit8)]
[InputControl(name = "9", displayName = "9", layout = "Key", bit = (int)Key.Digit9)]
[InputControl(name = "0", displayName = "0", layout = "Key", bit = (int)Key.Digit0)]
[InputControl(name = "leftShift", displayName = "Left Shift", layout = "Key", usage = "Modifier", bit = (int)Key.LeftShift)]
[InputControl(name = "rightShift", displayName = "Right Shift", layout = "Key", usage = "Modifier", bit = (int)Key.RightShift)]
[InputControl(name = "shift", displayName = "Shift", layout = "DiscreteButton", usage = "Modifier", bit = (int)Key.LeftShift, sizeInBits = 2, synthetic = true, parameters = "minValue=1,maxValue=3,writeMode=1")]
[InputControl(name = "leftAlt", displayName = "Left Alt", layout = "Key", usage = "Modifier", bit = (int)Key.LeftAlt)]
[InputControl(name = "rightAlt", displayName = "Right Alt", layout = "Key", usage = "Modifier", bit = (int)Key.RightAlt, alias = "AltGr")]
[InputControl(name = "alt", displayName = "Alt", layout = "DiscreteButton", usage = "Modifier", bit = (int)Key.LeftAlt, sizeInBits = 2, synthetic = true, parameters = "minValue=1,maxValue=3,writeMode=1")]
[InputControl(name = "leftCtrl", displayName = "Left Control", layout = "Key", usage = "Modifier", bit = (int)Key.LeftCtrl)]
[InputControl(name = "rightCtrl", displayName = "Right Control", layout = "Key", usage = "Modifier", bit = (int)Key.RightCtrl)]
[InputControl(name = "ctrl", displayName = "Control", layout = "DiscreteButton", usage = "Modifier", bit = (int)Key.LeftCtrl, sizeInBits = 2, synthetic = true, parameters = "minValue=1,maxValue=3,writeMode=1")]
[InputControl(name = "leftMeta", displayName = "Left System", layout = "Key", usage = "Modifier", bit = (int)Key.LeftMeta, aliases = new[] { "LeftWindows", "LeftApple", "LeftCommand" })]
[InputControl(name = "rightMeta", displayName = "Right System", layout = "Key", usage = "Modifier", bit = (int)Key.RightMeta, aliases = new[] { "RightWindows", "RightApple", "RightCommand" })]
[InputControl(name = "contextMenu", displayName = "Context Menu", layout = "Key", usage = "Modifier", bit = (int)Key.ContextMenu)]
[InputControl(name = "backspace", displayName = "Backspace", layout = "Key", bit = (int)Key.Backspace)]
[InputControl(name = "pageDown", displayName = "Page Down", layout = "Key", bit = (int)Key.PageDown)]
[InputControl(name = "pageUp", displayName = "Page Up", layout = "Key", bit = (int)Key.PageUp)]
[InputControl(name = "home", displayName = "Home", layout = "Key", bit = (int)Key.Home)]
[InputControl(name = "end", displayName = "End", layout = "Key", bit = (int)Key.End)]
[InputControl(name = "insert", displayName = "Insert", layout = "Key", bit = (int)Key.Insert)]
[InputControl(name = "delete", displayName = "Delete", layout = "Key", bit = (int)Key.Delete)]
[InputControl(name = "capsLock", displayName = "Caps Lock", layout = "Key", bit = (int)Key.CapsLock)]
[InputControl(name = "numLock", displayName = "Num Lock", layout = "Key", bit = (int)Key.NumLock)]
[InputControl(name = "printScreen", displayName = "Print Screen", layout = "Key", bit = (int)Key.PrintScreen)]
[InputControl(name = "scrollLock", displayName = "Scroll Lock", layout = "Key", bit = (int)Key.ScrollLock)]
[InputControl(name = "pause", displayName = "Pause/Break", layout = "Key", bit = (int)Key.Pause)]
[InputControl(name = "numpadEnter", displayName = "Numpad Enter", layout = "Key", bit = (int)Key.NumpadEnter)]
[InputControl(name = "numpadDivide", displayName = "Numpad /", layout = "Key", bit = (int)Key.NumpadDivide)]
[InputControl(name = "numpadMultiply", displayName = "Numpad *", layout = "Key", bit = (int)Key.NumpadMultiply)]
[InputControl(name = "numpadPlus", displayName = "Numpad +", layout = "Key", bit = (int)Key.NumpadPlus)]
[InputControl(name = "numpadMinus", displayName = "Numpad -", layout = "Key", bit = (int)Key.NumpadMinus)]
[InputControl(name = "numpadPeriod", displayName = "Numpad .", layout = "Key", bit = (int)Key.NumpadPeriod)]
[InputControl(name = "numpadEquals", displayName = "Numpad =", layout = "Key", bit = (int)Key.NumpadEquals)]
[InputControl(name = "numpad1", displayName = "Numpad 1", layout = "Key", bit = (int)Key.Numpad1)]
[InputControl(name = "numpad2", displayName = "Numpad 2", layout = "Key", bit = (int)Key.Numpad2)]
[InputControl(name = "numpad3", displayName = "Numpad 3", layout = "Key", bit = (int)Key.Numpad3)]
[InputControl(name = "numpad4", displayName = "Numpad 4", layout = "Key", bit = (int)Key.Numpad4)]
[InputControl(name = "numpad5", displayName = "Numpad 5", layout = "Key", bit = (int)Key.Numpad5)]
[InputControl(name = "numpad6", displayName = "Numpad 6", layout = "Key", bit = (int)Key.Numpad6)]
[InputControl(name = "numpad7", displayName = "Numpad 7", layout = "Key", bit = (int)Key.Numpad7)]
[InputControl(name = "numpad8", displayName = "Numpad 8", layout = "Key", bit = (int)Key.Numpad8)]
[InputControl(name = "numpad9", displayName = "Numpad 9", layout = "Key", bit = (int)Key.Numpad9)]
[InputControl(name = "numpad0", displayName = "Numpad 0", layout = "Key", bit = (int)Key.Numpad0)]
[InputControl(name = "f1", displayName = "F1", layout = "Key", bit = (int)Key.F1)]
[InputControl(name = "f2", displayName = "F2", layout = "Key", bit = (int)Key.F2)]
[InputControl(name = "f3", displayName = "F3", layout = "Key", bit = (int)Key.F3)]
[InputControl(name = "f4", displayName = "F4", layout = "Key", bit = (int)Key.F4)]
[InputControl(name = "f5", displayName = "F5", layout = "Key", bit = (int)Key.F5)]
[InputControl(name = "f6", displayName = "F6", layout = "Key", bit = (int)Key.F6)]
[InputControl(name = "f7", displayName = "F7", layout = "Key", bit = (int)Key.F7)]
[InputControl(name = "f8", displayName = "F8", layout = "Key", bit = (int)Key.F8)]
[InputControl(name = "f9", displayName = "F9", layout = "Key", bit = (int)Key.F9)]
[InputControl(name = "f10", displayName = "F10", layout = "Key", bit = (int)Key.F10)]
[InputControl(name = "f11", displayName = "F11", layout = "Key", bit = (int)Key.F11)]
[InputControl(name = "f12", displayName = "F12", layout = "Key", bit = (int)Key.F12)]
[InputControl(name = "OEM1", layout = "Key", bit = (int)Key.OEM1)]
[InputControl(name = "OEM2", layout = "Key", bit = (int)Key.OEM2)]
[InputControl(name = "OEM3", layout = "Key", bit = (int)Key.OEM3)]
[InputControl(name = "OEM4", layout = "Key", bit = (int)Key.OEM4)]
[InputControl(name = "OEM5", layout = "Key", bit = (int)Key.OEM5)]
[InputControl(name = "IMESelected", layout = "Button", bit = (int)Key.IMESelected, synthetic = true)]
public fixed byte keys[kSizeInBytes];
public KeyboardState(params Key[] pressedKeys)
{
if (pressedKeys == null)
throw new ArgumentNullException(nameof(pressedKeys));
fixed(byte* keysPtr = keys)
{
UnsafeUtility.MemClear(keysPtr, kSizeInBytes);
for (var i = 0; i < pressedKeys.Length; ++i)
MemoryHelpers.WriteSingleBit(keysPtr, (uint)pressedKeys[i], true);
}
}
public void Set(Key key, bool state)
{
fixed(byte* keysPtr = keys)
MemoryHelpers.WriteSingleBit(keysPtr, (uint)key, state);
}
public void Press(Key key)
{
Set(key, true);
}
public void Release(Key key)
{
Set(key, false);
}
public FourCC format => Format;
}
}
namespace UnityEngine.InputSystem
{
///
/// Enumeration of key codes.
///
///
/// Named according to the US keyboard layout which is used as a reference layout. Note, however,
/// that keys are identified by physical location, not by the characters they generate. This means,
/// for example, that is always the key to the right of ,
/// regardless of which key (if any) produces the "a" character on the current keyboard layout.
///
/// To find the text character (if any) generated by a key according to the currently active keyboard
/// layout, use the property of .
///
///
///
/// // Look up key by key code.
/// var aKey = Keyboard.current[Key.A];
///
/// // Find out which text is produced by the key.
/// Debug.Log($"The '{aKey.keyCode}' key produces '{aKey.displayName}' as text input");
///
///
///
// NOTE: Has to match up with 'KeyboardInputState::KeyCode' in native.
// NOTE: In the keyboard code, we depend on the order of the keys in the various keyboard blocks.
public enum Key
{
///
/// Invalid key. Does not represent a key on the keyboard and is only used to have a
/// default for the Key enumeration not represent any specific key.
///
None,
// ---- Printable keys ----
///
/// The .
///
Space,
///
/// The .
///
Enter,
///
/// The .
///
Tab,
///
/// The .
///
Backquote,
///
/// The .
///
Quote,
///
/// The .
///
Semicolon,
///
/// The .
///
Comma,
///
/// The .
///
Period,
///
/// The .
///
Slash,
///
/// The .
///
Backslash,
///
/// The .
///
LeftBracket,
///
/// The .
///
RightBracket,
///
/// The .
///
Minus,
///
/// The .
///
Equals,
///
/// The .
///
A,
///
/// The .
///
B,
///
/// The .
///
C,
///
/// The .
///
D,
///
/// The .
///
E,
///
/// The .
///
F,
///
/// The .
///
G,
///
/// The .
///
H,
///
/// The .
///
I,
///
/// The .
///
J,
///
/// The .
///
K,
///
/// The .
///
L,
///
/// The .
///
M,
///
/// The .
///
N,
///
/// The .
///
O,
///
/// The .
///
P,
///
/// The .
///
Q,
///
/// The .
///
R,
///
/// The .
///
S,
///
/// The .
///
T,
///
/// The .
///
U,
///
/// The .
///
V,
///
/// The .
///
W,
///
/// The .
///
X,
///
/// The .
///
Y,
///
/// The .
///
Z,
///
/// The .
///
Digit1,
///
/// The .
///
Digit2,
///
/// The .
///
Digit3,
///
/// The .
///
Digit4,
///
/// The .
///
Digit5,
///
/// The .
///
Digit6,
///
/// The .
///
Digit7,
///
/// The .
///
Digit8,
///
/// The .
///
Digit9,
///
/// The .
///
Digit0,
// ---- Non-printable keys ----
// NOTE: The left&right variants for shift, ctrl, and alt must be next to each other.
///
/// The .
///
LeftShift,
///
/// The .
///
RightShift,
///
/// The .
///
LeftAlt,
///
/// The .
///
RightAlt,
///
/// Same as .
///
AltGr = RightAlt,
///
/// The .
///
LeftCtrl,
///
/// The .
///
RightCtrl,
///
/// The .
///
LeftMeta,
///
/// The .
///
RightMeta,
///
/// Same as .
///
LeftWindows = LeftMeta,
///
/// Same as .
///
RightWindows = RightMeta,
///
/// Same as .
///
LeftApple = LeftMeta,
///
/// Same as .
///
RightApple = RightMeta,
///
/// Same as .
///
LeftCommand = LeftMeta,
///
/// Same as .
///
RightCommand = RightMeta,
///
/// The .
///
ContextMenu,
///
/// The .
///
Escape,
///
/// The .
///
LeftArrow,
///
/// The .
///
RightArrow,
///
/// The .
///
UpArrow,
///
/// The .
///
DownArrow,
///
/// The .
///
Backspace,
///
/// The .
///
PageDown,
///
/// The .
///
PageUp,
///
/// The .
///
Home,
///
/// The .
///
End,
///
/// The .
///
Insert,
///
/// The .
///
Delete,
///
/// The .
///
CapsLock,
///
/// The .
///
NumLock,
///
/// The .
///
PrintScreen,
///
/// The .
///
ScrollLock,
///
/// The .
///
Pause,
// ---- Numpad ----
// NOTE: Numpad layout follows the 18-key numpad layout. Some PC keyboards
// have a 17-key numpad layout where the plus key is an elongated key
// like the numpad enter key. Be aware that in those layouts the positions
// of some of the operator keys are also different. However, we stay
// layout neutral here, too, and always use the 18-key blueprint.
///
/// The .
///
NumpadEnter,
///
/// The .
///
NumpadDivide,
///
/// The .
///
NumpadMultiply,
///
/// The .
///
NumpadPlus,
///
/// The .
///
NumpadMinus,
///
/// The .
///
NumpadPeriod,
///
/// The .
///
NumpadEquals,
///
/// The .
///
Numpad0,
///
/// The .
///
Numpad1,
///
/// The .
///
Numpad2,
///
/// The .
///
Numpad3,
///
/// The .
///
Numpad4,
///
/// The .
///
Numpad5,
///
/// The .
///
Numpad6,
///
/// The .
///
Numpad7,
///
/// The .
///
Numpad8,
///
/// The .
///
Numpad9,
///
/// The .
///
F1,
///
/// The .
///
F2,
///
/// The .
///
F3,
///
/// The .
///
F4,
///
/// The .
///
F5,
///
/// The .
///
F6,
///
/// The .
///
F7,
///
/// The .
///
F8,
///
/// The .
///
F9,
///
/// The .
///
F10,
///
/// The .
///
F11,
///
/// The .
///
F12,
// Extra keys that a keyboard may have. We make no guarantees about where
// they end up on the keyboard (if they are present).
///
/// The .
///
OEM1,
///
/// The .
///
OEM2,
///
/// The .
///
OEM3,
///
/// The .
///
OEM4,
///
/// The .
///
OEM5,
////FIXME: This should never have been a Key but rather just an extra button or state on keyboard
// Not exactly a key, but binary data sent by the Keyboard to say if IME is being used.
IMESelected
}
///
/// Represents a standard, physical PC-type keyboard.
///
///
/// Keyboards allow for both individual button input as well as text input. To receive button
/// input, use the individual -type controls present on the keyboard.
/// For example, . To receive text input, use the
/// callback.
///
/// The naming/identification of keys is agnostic to keyboard layouts. This means that ,
/// for example, will always be the key to the right of regardless of where
/// the current keyboard language layout puts the "a" character. This also means that having a
/// binding to "<Keyboard>/a" on an , 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 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
/// property. Note that keyboard layout names are platform-dependent.
///
/// Note that keyboard devices will always have key controls added for all keys in the
/// 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.
///
[InputControlLayout(stateType = typeof(KeyboardState), isGenericTypeOfDevice = true)]
public class Keyboard : InputDevice, ITextInputReceiver
{
///
/// Total number of key controls on a keyboard, i.e. the number of controls
/// in .
///
/// Total number of key controls.
public const int KeyCount = (int)Key.OEM5;
///
/// Event that is fired for every single character entered on the keyboard.
///
/// Triggered whenever the keyboard receives text input.
///
///
///
/// // 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();
/// }
/// }
/// }
///
///
///
public event Action onTextInput
{
add
{
if (value == null)
throw new ArgumentNullException(nameof(value));
if (!m_TextInputListeners.Contains(value))
m_TextInputListeners.Append(value);
}
remove => m_TextInputListeners.Remove(value);
}
///
/// 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.
///
///
/// 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 for turning IME on/off
///
public event Action onIMECompositionChange
{
add
{
if (value == null)
throw new ArgumentNullException(nameof(value));
if (!m_ImeCompositionListeners.Contains(value))
m_ImeCompositionListeners.Append(value);
}
remove => m_ImeCompositionListeners.Remove(value);
}
///
/// Activates/deactivates IME composition while typing. This decides whether or not to use the OS supplied IME system.
///
///
///
/// 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 , ,
/// for more IME settings and data.
///
public void SetIMEEnabled(bool enabled)
{
var command = EnableIMECompositionCommand.Create(enabled);
ExecuteCommand(ref command);
}
///
/// Sets the cursor position for IME composition dialogs. Units are from the upper left, in pixels, moving down and to the right.
///
///
/// 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 for turning IME on/off
///
public void SetIMECursorPosition(Vector2 position)
{
SetIMECursorPositionCommand command = SetIMECursorPositionCommand.Create(position);
ExecuteCommand(ref command);
}
///
/// The name of the layout currently used by the keyboard.
///
///
/// 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 .
///
public string keyboardLayout
{
get
{
RefreshConfigurationIfNeeded();
return m_KeyboardLayoutName;
}
protected set => m_KeyboardLayoutName = value;
}
///
/// A synthetic button control that is considered pressed if any key on the keyboard is pressed.
///
/// Control representing the synthetic "anyKey".
public AnyKeyControl anyKey { get; protected set; }
///
/// The space bar key.
///
/// Control representing the space bar key.
public KeyControl spaceKey => this[Key.Space];
///
/// The enter/return key in the main key block.
///
/// Control representing the enter key.
///
/// This key is distinct from the enter key on the numpad which is .
///
public KeyControl enterKey => this[Key.Enter];
///
/// The tab key.
///
/// Control representing the tab key.
public KeyControl tabKey => this[Key.Tab];
///
/// The ` key. The leftmost key in the row of digits. Directly above .
///
/// Control representing the backtick/quote key.
public KeyControl backquoteKey => this[Key.Backquote];
///
/// The ' key. The key immediately to the left of .
///
/// Control representing the quote key.
public KeyControl quoteKey => this[Key.Quote];
///
/// The ';' key. The key immediately to the left of .
///
/// Control representing the semicolon key.
public KeyControl semicolonKey => this[Key.Semicolon];
///
/// The ',' key. Third key to the left of .
///
/// Control representing the comma key.
public KeyControl commaKey => this[Key.Comma];
///
/// The '.' key. Second key to the left of .
///
/// Control representing the period key.
public KeyControl periodKey => this[Key.Period];
///
/// The '/' key. The key immediately to the left of .
///
/// Control representing the forward slash key.
public KeyControl slashKey => this[Key.Slash];
///
/// The '\' key. The key immediately to the right of and
/// next to or above .
///
/// Control representing the backslash key.
public KeyControl backslashKey => this[Key.Backslash];
///
/// The '[' key. The key immediately to the left of .
///
/// Control representing the left bracket key.
public KeyControl leftBracketKey => this[Key.LeftBracket];
///
/// The ']' key. The key in-between to the left and
/// to the right.
///
/// Control representing the right bracket key.
public KeyControl rightBracketKey => this[Key.RightBracket];
///
/// The '-' key. The second key to the left of .
///
/// Control representing the minus key.
public KeyControl minusKey => this[Key.Minus];
///
/// The '=' key in the main key block. The key in-between to the left
/// and to the right.
///
/// Control representing the equals key.
public KeyControl equalsKey => this[Key.Equals];
///
/// The 'a' key. The key immediately to the right of .
///
/// Control representing the a key.
public KeyControl aKey => this[Key.A];
///
/// The 'b' key. The key in-between the to the left and the
/// to the right in the bottom-most row of alphabetic characters.
///
/// Control representing the b key.
public KeyControl bKey => this[Key.B];
///
/// The 'c' key. The key in-between the to the left and the
/// to the right in the bottom-most row of alphabetic characters.
///
/// Control representing the c key.
public KeyControl cKey => this[Key.C];
///
/// The 'd' key. The key in-between the to the left and the
/// to the right in the middle row of alphabetic characters.
///
/// Control representing the d key.
public KeyControl dKey => this[Key.D];
///
/// The 'e' key. The key in-between the to the left and the
/// to the right in the topmost row of alphabetic characters.
///
/// Control representing the e key.
public KeyControl eKey => this[Key.E];
///
/// The 'f' key. The key in-between the to the left and the
/// to the right in the middle row of alphabetic characters.
///
/// Control representing the f key.
public KeyControl fKey => this[Key.F];
///
/// The 'g' key. The key in-between the to the left and the
/// to the right in the middle row of alphabetic characters.
///
/// Control representing the g key.
public KeyControl gKey => this[Key.G];
///
/// The 'h' key. The key in-between the to the left and the
/// to the right in the middle row of alphabetic characters.
///
/// Control representing the h key.
public KeyControl hKey => this[Key.H];
///
/// The 'i' key. The key in-between the to the left and the
/// to the right in the top row of alphabetic characters.
///
public KeyControl iKey => this[Key.I];
///
/// The 'j' key. The key in-between the to the left and the
/// to the right in the middle row of alphabetic characters.
///
/// Control representing the j key.
public KeyControl jKey => this[Key.J];
///
/// The 'k' key. The key in-between the to the left and the
/// to the right in the middle row of alphabetic characters.
///
/// Control representing the k key.
public KeyControl kKey => this[Key.K];
///
/// The 'l' key. The key in-between the to the left and the
/// to the right in the middle row of alphabetic characters.
///
/// Control representing the l key.
public KeyControl lKey => this[Key.L];
///
/// The 'm' key. The key in-between the to the left and the
/// to the right in the bottom row of alphabetic characters.
///
/// Control representing the m key.
public KeyControl mKey => this[Key.M];
///
/// The 'n' key. The key in-between the to the left and the to
/// the right in the bottom row of alphabetic characters.
///
/// Control representing the n key.
public KeyControl nKey => this[Key.N];
///
/// The 'o' key. The key in-between the to the left and the to
/// the right in the top row of alphabetic characters.
///
/// Control representing the o key.
public KeyControl oKey => this[Key.O];
///
/// The 'p' key. The key in-between the to the left and the
/// to the right in the top row of alphabetic characters.
///
/// Control representing the p key.
public KeyControl pKey => this[Key.P];
///
/// The 'q' key. The key in-between the to the left and the
/// to the right in the top row of alphabetic characters.
///
/// Control representing the q key.
public KeyControl qKey => this[Key.Q];
///
/// The 'r' key. The key in-between the to the left and the
/// to the right in the top row of alphabetic characters.
///
/// Control representing the r key.
public KeyControl rKey => this[Key.R];
///
/// The 's' key. The key in-between the to the left and the
/// to the right in the middle row of alphabetic characters.
///
/// Control representing the s key.
public KeyControl sKey => this[Key.S];
///
/// The 't' key. The key in-between the to the left and the
/// to the right in the top row of alphabetic characters.
///
/// Control representing the t key.
public KeyControl tKey => this[Key.T];
///
/// The 'u' key. The key in-between the to the left and the
/// to the right in the top row of alphabetic characters.
///
/// Control representing the u key.
public KeyControl uKey => this[Key.U];
///
/// The 'v' key. The key in-between the to the left and the
/// to the right in the bottom row of alphabetic characters.
///
/// Control representing the v key.
public KeyControl vKey => this[Key.V];
///
/// The 'w' key. The key in-between the to the left and the
/// to the right in the top row of alphabetic characters.
///
/// Control representing the w key.
public KeyControl wKey => this[Key.W];
///
/// The 'x' key. The key in-between the to the left and the
/// to the right in the bottom row of alphabetic characters.
///
/// Control representing the x key.
public KeyControl xKey => this[Key.X];
///
/// The 'y' key. The key in-between the to the left and the
/// to the right in the top row of alphabetic characters.
///
/// Control representing the y key.
public KeyControl yKey => this[Key.Y];
///
/// The 'z' key. The key in-between the to the left and the
/// to the right in the bottom row of alphabetic characters.
///
/// Control representing the z key.
public KeyControl zKey => this[Key.Z];
///
/// The '1' key. The key in-between the to the left and the
/// to the right in the row of digit characters.
///
/// Control representing the 1 key.
public KeyControl digit1Key => this[Key.Digit1];
///
/// The '2' key. The key in-between the to the left and the
/// to the right in the row of digit characters.
///
/// Control representing the 2 key.
public KeyControl digit2Key => this[Key.Digit2];
///
/// The '3' key. The key in-between the to the left and the
/// to the right in the row of digit characters.
///
/// Control representing the 3 key.
public KeyControl digit3Key => this[Key.Digit3];
///
/// The '4' key. The key in-between the to the left and the
/// to the right in the row of digit characters.
///
/// Control representing the 4 key.
public KeyControl digit4Key => this[Key.Digit4];
///
/// The '5' key. The key in-between the to the left and the
/// to the right in the row of digit characters.
///
/// Control representing the 5 key.
public KeyControl digit5Key => this[Key.Digit5];
///
/// The '6' key. The key in-between the to the left and the
/// to the right in the row of digit characters.
///
/// Control representing the 6 key.
public KeyControl digit6Key => this[Key.Digit6];
///
/// The '7' key. The key in-between the to the left and the
/// to the right in the row of digit characters.
///
/// Control representing the 7 key.
public KeyControl digit7Key => this[Key.Digit7];
///
/// The '8' key. The key in-between the to the left and the
/// to the right in the row of digit characters.
///
/// Control representing the 8 key.
public KeyControl digit8Key => this[Key.Digit8];
///
/// The '9' key. The key in-between the to the left and the
/// to the right in the row of digit characters.
///
/// Control representing the 9 key.
public KeyControl digit9Key => this[Key.Digit9];
///
/// The '0' key. The key in-between the to the left and the
/// to the right in the row of digit characters.
///
/// Control representing the 0 key.
public KeyControl digit0Key => this[Key.Digit0];
///
/// The shift key on the left side of the keyboard.
///
/// Control representing the left shift key.
public KeyControl leftShiftKey => this[Key.LeftShift];
///
/// The shift key on the right side of the keyboard.
///
/// Control representing the right shift key.
public KeyControl rightShiftKey => this[Key.RightShift];
///
/// The alt/option key on the left side of the keyboard.
///
/// Control representing the left alt/option key.
public KeyControl leftAltKey => this[Key.LeftAlt];
///
/// The alt/option key on the right side of the keyboard.
///
/// Control representing the right alt/option key.
public KeyControl rightAltKey => this[Key.RightAlt];
///
/// The control/ctrl key on the left side of the keyboard.
///
/// Control representing the left control key.
public KeyControl leftCtrlKey => this[Key.LeftCtrl];
///
/// The control/ctrl key on the right side of the keyboard.
///
/// This key is usually not present on Mac laptops.
/// Control representing the right control key.
public KeyControl rightCtrlKey => this[Key.RightCtrl];
///
/// The system "meta" key (Windows key on PC, Apple/command key on Mac) on the left
/// side of the keyboard.
///
/// Control representing the left system meta key.
public KeyControl leftMetaKey => this[Key.LeftMeta];
///
/// The system "meta" key (Windows key on PC, Apple/command key on Mac) on the right
/// side of the keyboard.
///
/// Control representing the right system meta key.
public KeyControl rightMetaKey => this[Key.RightMeta];
///
/// Same as . Windows system key on left side of keyboard.
///
/// Control representing the left Windows system key.
public KeyControl leftWindowsKey => this[Key.LeftWindows];
///
/// Same as . Windows system key on right side of keyboard.
///
/// Control representing the right Windows system key.
public KeyControl rightWindowsKey => this[Key.RightWindows];
///
/// Same as . Apple/command system key on left side of keyboard.
///
/// Control representing the left Apple/command system key.
public KeyControl leftAppleKey => this[Key.LeftApple];
///
/// Same as . Apple/command system key on right side of keyboard.
///
/// Control representing the right Apple/command system key.
public KeyControl rightAppleKey => this[Key.RightApple];
///
/// Same as . Apple/command system key on left side of keyboard.
///
/// Control representing the left Apple/command system key.
public KeyControl leftCommandKey => this[Key.LeftCommand];
///
/// Same as . Apple/command system key on right side of keyboard.
///
/// Control representing the right Apple/command system key.
public KeyControl rightCommandKey => this[Key.RightCommand];
///
/// The context menu key. This key is generally only found on PC keyboards. If present,
/// the key is found in-between the to the left and the
/// to the right. It's intention is to bring up the context
/// menu according to the current selection.
///
/// Control representing the context menu key.
public KeyControl contextMenuKey => this[Key.ContextMenu];
///
/// The escape key, i.e. the key generally in the top left corner of the keyboard.
/// Usually to the left of .
///
/// Control representing the escape key.
public KeyControl escapeKey => this[Key.Escape];
///
/// The left arrow key. Usually in a block by itself and generally to the left
/// of .
///
/// Control representing the left arrow key.
public KeyControl leftArrowKey => this[Key.LeftArrow];
///
/// The right arrow key. Usually in a block by itself and generally to the right
/// of
///
/// Control representing the right arrow key.
public KeyControl rightArrowKey => this[Key.RightArrow];
///
/// The up arrow key. Usually in a block by itself and generally on top of the
/// .
///
/// Control representing the up arrow key.
public KeyControl upArrowKey => this[Key.UpArrow];
///
/// The down arrow key. Usually in a block by itself and generally below the
/// and in-between to the
/// left and to the right.
///
/// Control representing the down arrow key.
public KeyControl downArrowKey => this[Key.DownArrow];
///
/// The backspace key (usually labeled "delete" on Mac). The rightmost key
/// in the top digit row with to the left.
///
/// Control representing the backspace key.
///
/// On the Mac, this key may be labeled "delete" which however is a
/// key different from .
///
public KeyControl backspaceKey => this[Key.Backspace];
///
/// The page down key. Usually in a separate block with
/// to the left and above it.
///
/// Control representing the page down key.
public KeyControl pageDownKey => this[Key.PageDown];
///
/// The page up key. Usually in a separate block with
/// to the left and below it.
///
/// Control representing the page up key.
public KeyControl pageUpKey => this[Key.PageUp];
///
/// The 'home' key. Usually in a separate block with
/// to the right and to the left.
///
/// Control representing the insert key.
public KeyControl homeKey => this[Key.Home];
///
/// The 'end' key. Usually in a separate block with
/// to the left and to the right.
///
/// Control representing the end key.
public KeyControl endKey => this[Key.End];
///
/// The 'insert' key. Usually in a separate block with
/// to its right and sitting below it.
///
/// Control representing the insert key.
public KeyControl insertKey => this[Key.Insert];
///
/// The 'delete' key. Usually in a separate block with
/// to its right and sitting above it.
///
/// Control representing the delete key.
///
/// On the Mac, the is also labeled "delete".
/// However, this is not this key.
///
public KeyControl deleteKey => this[Key.Delete];
///
/// The Caps Lock key. The key below and above
/// .
///
/// Control representing the caps lock key.
public KeyControl capsLockKey => this[Key.CapsLock];
///
/// The Scroll Lock key. The key in-between the
/// to the left and the to the right. May also
/// be labeled "F14".
///
/// Control representing the scroll lock key.
public KeyControl scrollLockKey => this[Key.ScrollLock];
///
/// 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.
///
/// Control representing the num lock key.
public KeyControl numLockKey => this[Key.NumLock];
///
/// The Print Screen key. The key sitting in-between
/// to the left and to the right. May also
/// be labeled "F13".
///
/// Control representing the print screen key.
public KeyControl printScreenKey => this[Key.PrintScreen];
///
/// The pause/break key. The key sitting to the left of .
/// May also be labeled "F15".
///
/// Control representing the pause/break key.
public KeyControl pauseKey => this[Key.Pause];
///
/// The enter key on the numpad. The key sitting in the bottom right corner
/// of the numpad.
///
/// Control representing the numpad enter key.
public KeyControl numpadEnterKey => this[Key.NumpadEnter];
///
/// The divide ('/') key on the numpad. The key in-between
/// to the left and to the right.
///
/// Control representing the numpad divide 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 on PC keyboards.
///
public KeyControl numpadDivideKey => this[Key.NumpadDivide];
///
/// The multiply ('*') key on the numpad. The key in the upper right corner of the numpad
/// with to the left and
/// below it.
///
/// Control representing the numpad multiply 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 on PC keyboards.
///
public KeyControl numpadMultiplyKey => this[Key.NumpadMultiply];
///
/// The minus ('-') key on the numpad. The key on the right side of the numpad with
/// above it and below it.
///
/// Control representing the numpad minus 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 that covers the space of two keys.
///
public KeyControl numpadMinusKey => this[Key.NumpadMinus];
///
/// The plus ('+') key on the numpad. The key on the right side of the numpad with
/// above it and below it.
///
/// Control representing the numpad plus 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
/// 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.
///
public KeyControl numpadPlusKey => this[Key.NumpadPlus];
///
/// The period ('.') key on the numpad. The key in-between the
/// to the right and the to the left.
///
/// Control representing the numpad period key.
///
/// This key is the same in 17-key and 18-key numpad layouts.
///
public KeyControl numpadPeriodKey => this[Key.NumpadPeriod];
///
/// The equals ('=') key on the numpad. The key in-between to the left
/// and to the right in the top row of the numpad.
///
/// Control representing the numpad equals 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.
///
public KeyControl numpadEqualsKey => this[Key.NumpadEquals];
///
/// The 0 key on the numpad. The key in the bottom left corner of the numpad. Usually
/// and elongated key.
///
/// Control representing the numpad 0 key.
public KeyControl numpad0Key => this[Key.Numpad0];
///
/// The 1 key on the numpad. The key on the left side of the numpad with
/// below it and above it.
///
/// Control representing the numpad 1 key.
public KeyControl numpad1Key => this[Key.Numpad1];
///
/// The 2 key on the numpad. The key with the to its left and
/// the to its right.
///
/// Control representing the numpad 2 key.
public KeyControl numpad2Key => this[Key.Numpad2];
///
/// The 3 key on the numpad. The key with the to its left and
/// the to its right.
///
/// Control representing the numpad 3 key.
public KeyControl numpad3Key => this[Key.Numpad3];
///
/// The 4 key on the numpad. The key on the left side of the numpad with the
/// below it and the above it.
///
/// Control representing the numpad 4 key.
public KeyControl numpad4Key => this[Key.Numpad4];
///
/// The 5 key on the numpad. The key in-between the to the left and the
/// to the right.
///
/// Control representing the numpad 5 key.
public KeyControl numpad5Key => this[Key.Numpad5];
///
/// The 6 key on the numpad. The key in-between the to the let and
/// the to the right.
///
/// Control representing the numpad 6 key.
public KeyControl numpad6Key => this[Key.Numpad6];
///
/// The 7 key on the numpad. The key on the left side of the numpad with
/// below it and above it.
///
/// Control representing the numpad 7 key.
public KeyControl numpad7Key => this[Key.Numpad7];
///
/// The 8 key on the numpad. The key in-between the to the left and the
/// to the right.
///
/// Control representing the numpad 8 key.
public KeyControl numpad8Key => this[Key.Numpad8];
///
/// The 9 key on the numpad. The key in-between the to the left and
/// the to the right (or, on 17-key PC keyboard numpads, the elongated
/// plus key).
///
/// Control representing the numpad 9 key.
public KeyControl numpad9Key => this[Key.Numpad9];
///
/// The F1 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F1 key.
public KeyControl f1Key => this[Key.F1];
///
/// The F2 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F2 key.
public KeyControl f2Key => this[Key.F2];
///
/// The F3 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F3 key.
public KeyControl f3Key => this[Key.F3];
///
/// The F4 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F4 key.
public KeyControl f4Key => this[Key.F4];
///
/// The F5 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F5 key.
public KeyControl f5Key => this[Key.F5];
///
/// The F6 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F6 key.
public KeyControl f6Key => this[Key.F6];
///
/// The F7 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F7 key.
public KeyControl f7Key => this[Key.F7];
///
/// The F8 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F8 key.
public KeyControl f8Key => this[Key.F8];
///
/// The F9 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F9 key.
public KeyControl f9Key => this[Key.F9];
///
/// The F10 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F10 key.
public KeyControl f10Key => this[Key.F10];
///
/// The F11 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F11 key.
public KeyControl f11Key => this[Key.F11];
///
/// The F12 key. The key in-between to the left and
/// to the right in the topmost row of keys.
///
/// Control representing the F12 key.
public KeyControl f12Key => this[Key.F12];
///
/// First additional key on the keyboard.
///
/// Control representing .
///
/// 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 and .
///
/// 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.
///
public KeyControl oem1Key => this[Key.OEM1];
///
/// Second additional key on the keyboard.
///
/// Control representing .
///
/// 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 and .
///
/// 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.
///
public KeyControl oem2Key => this[Key.OEM2];
///
/// Third additional key on the keyboard.
///
/// Control representing .
///
/// 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 and .
///
/// 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.
///
public KeyControl oem3Key => this[Key.OEM3];
///
/// Fourth additional key on the keyboard.
///
/// Control representing .
///
/// 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 and .
///
/// 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.
///
public KeyControl oem4Key => this[Key.OEM4];
///
/// Fifth additional key on the keyboard.
///
/// Control representing .
///
/// 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 and .
///
/// 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.
///
public KeyControl oem5Key => this[Key.OEM5];
///
/// An artificial combination of and into one control.
///
/// Control representing a combined left and right shift key.
///
/// This is a button which is considered pressed whenever the left and/or
/// right shift key is pressed.
///
public ButtonControl shiftKey { get; protected set; }
///
/// An artificial combination of and into one control.
///
/// Control representing a combined left and right ctrl key.
///
/// This is a button which is considered pressed whenever the left and/or
/// right ctrl key is pressed.
///
public ButtonControl ctrlKey { get; protected set; }
///
/// An artificial combination of and into one control.
///
/// Control representing a combined left and right alt key.
///
/// This is a button which is considered pressed whenever the left and/or
/// right alt key is pressed.
///
public ButtonControl altKey { get; protected set; }
///
/// True when IME composition is enabled. Requires to be called to enable IME, and the user to enable it at the OS level.
///
///
///
/// 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 for turning IME on/off
///
public ButtonControl imeSelected { get; protected set; }
///
/// Look up a key control by its key code.
///
/// Key code of key control to return.
/// The given is not valid.
///
/// This is equivalent to allKeys[(int)key - 1].
///
public KeyControl this[Key key]
{
get
{
var index = (int)key - 1;
if (index < 0 || index >= m_Keys.Length)
throw new ArgumentOutOfRangeException(nameof(key));
return m_Keys[index];
}
}
///
/// List of all key controls on the keyboard.
///
public ReadOnlyArray allKeys => new ReadOnlyArray(m_Keys);
///
/// The keyboard that was last used or added. Null if there is no keyboard.
///
public static Keyboard current { get; private set; }
///
/// Make the keyboard the current keyboard (i.e. ).
///
///
/// A keyboard will automatically be made current when receiving input or when
/// added to the input system.
///
public override void MakeCurrent()
{
base.MakeCurrent();
current = this;
}
///
/// Called when the keyboard is removed from the system.
///
protected override void OnRemoved()
{
base.OnRemoved();
if (current == this)
current = null;
}
///
/// Called after the keyboard has been constructed but before it is added to
/// the system.
///
protected override void FinishSetup()
{
var keyStrings = new[]
{
"space",
"enter",
"tab",
"backquote",
"quote",
"semicolon",
"comma",
"period",
"slash",
"backslash",
"leftbracket",
"rightbracket",
"minus",
"equals",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0",
"leftshift",
"rightshift",
"leftalt",
"rightalt",
"leftctrl",
"rightctrl",
"leftmeta",
"rightmeta",
"contextmenu",
"escape",
"leftarrow",
"rightarrow",
"uparrow",
"downarrow",
"backspace",
"pagedown",
"pageup",
"home",
"end",
"insert",
"delete",
"capslock",
"numlock",
"printscreen",
"scrolllock",
"pause",
"numpadenter",
"numpaddivide",
"numpadmultiply",
"numpadplus",
"numpadminus",
"numpadperiod",
"numpadequals",
"numpad0",
"numpad1",
"numpad2",
"numpad3",
"numpad4",
"numpad5",
"numpad6",
"numpad7",
"numpad8",
"numpad9",
"f1",
"f2",
"f3",
"f4",
"f5",
"f6",
"f7",
"f8",
"f9",
"f10",
"f11",
"f12",
"oem1",
"oem2",
"oem3",
"oem4",
"oem5",
};
m_Keys = new KeyControl[keyStrings.Length];
for (var i = 0; i < keyStrings.Length; ++i)
{
m_Keys[i] = GetChildControl(keyStrings[i]);
////REVIEW: Ideally, we'd have a way to do this through layouts; this way nested key controls could work, too,
//// and it just seems somewhat dirty to jam the data into the control here
m_Keys[i].keyCode = (Key)(i + 1);
}
Debug.Assert(keyStrings[(int)Key.OEM5 - 1] == "oem5",
"keyString array layout doe not match Key enum layout");
anyKey = GetChildControl("anyKey");
shiftKey = GetChildControl("shift");
ctrlKey = GetChildControl("ctrl");
altKey = GetChildControl("alt");
imeSelected = GetChildControl("IMESelected");
base.FinishSetup();
}
///
protected override void RefreshConfiguration()
{
keyboardLayout = null;
var command = QueryKeyboardLayoutCommand.Create();
if (ExecuteCommand(ref command) >= 0)
keyboardLayout = command.ReadLayoutName();
}
///
/// Called when text input on the keyboard is received.
///
/// Character that has been entered.
///
/// The system will call this automatically whenever a is
/// received that targets the keyboard device.
///
public void OnTextInput(char character)
{
for (var i = 0; i < m_TextInputListeners.length; ++i)
m_TextInputListeners[i](character);
}
///
/// Return the key control that, according to the currently active keyboard layout (see ),
/// is associated with the given text.
///
/// Display name reported for the key according to the currently active keyboard layout.
/// The key control corresponding to the given text or null if no such key was found on the current
/// keyboard layout.
///
/// 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");
///
///
///
public KeyControl FindKeyOnCurrentKeyboardLayout(string displayName)
{
var keys = allKeys;
for (var i = 0; i < keys.Count; ++i)
if (string.Equals(keys[i].displayName, displayName, StringComparison.CurrentCultureIgnoreCase))
return keys[i];
return null;
}
public void OnIMECompositionChanged(IMECompositionString compositionString)
{
if (m_ImeCompositionListeners.length > 0)
{
for (var i = 0; i < m_ImeCompositionListeners.length; ++i)
m_ImeCompositionListeners[i](compositionString);
}
}
private InlinedArray> m_TextInputListeners;
private string m_KeyboardLayoutName;
private KeyControl[] m_Keys;
private InlinedArray> m_ImeCompositionListeners;
///
/// Raw array of key controls on the keyboard.
///
protected KeyControl[] keys
{
get => m_Keys;
set => m_Keys = value;
}
}
}