using UnityEngine.InputSystem.LowLevel; using UnityEngine.Scripting; namespace UnityEngine.InputSystem.Controls { /// /// A key on a . /// /// /// This is an extended button control which adds various features to account for the fact that keys /// have symbols associated with them which may change depending on keyboard layout as well as in combination /// with other keys. /// /// Note that there is no text input associated with individual keys as text composition is highly /// layout specific and does not need to be key-by-key. For general text input, see . /// To find the text displayed on a key, use . /// [Preserve] public class KeyControl : ButtonControl { /// /// The code used in Unity to identify the key. /// /// /// This property must be initialized by of /// the device owning the control. /// public Key keyCode { get; set; } ////REVIEW: rename this to something like platformKeyCode? We're not really dealing with scan code here. /// /// The code that the underlying platform uses to identify the key. /// public int scanCode { get { RefreshConfigurationIfNeeded(); return m_ScanCode; } } protected override void RefreshConfiguration() { // Wipe our last cached set of data (if any). displayName = null; m_ScanCode = 0; var command = QueryKeyNameCommand.Create(keyCode); if (device.ExecuteCommand(ref command) > 0) { m_ScanCode = command.scanOrKeyCode; displayName = command.ReadKeyName(); } } // Cached configuration data for the key. We fetch this from the // device on demand. private int m_ScanCode; } }