////REVIEW: move everything from InputControlExtensions here? namespace UnityEngine.InputSystem { /// /// Various useful extension methods. /// public static class InputExtensions { /// /// Return true if the given phase is or . /// /// An action phase. /// True if the phase is started or performed. /// public static bool IsInProgress(this InputActionPhase phase) { return phase == InputActionPhase.Started || phase == InputActionPhase.Performed; } /// /// Return true if the given phase is or , i.e. /// if a touch with that phase would no longer be ongoing. /// /// A touch phase. /// True if the phase indicates a touch that has ended. /// public static bool IsEndedOrCanceled(this TouchPhase phase) { return phase == TouchPhase.Canceled || phase == TouchPhase.Ended; } /// /// Return true if the given phase is , , or /// , i.e. if a touch with that phase would indicate an ongoing touch. /// /// A touch phase. /// True if the phase indicates a touch that is ongoing. /// public static bool IsActive(this TouchPhase phase) { switch (phase) { case TouchPhase.Began: case TouchPhase.Moved: case TouchPhase.Stationary: return true; } return false; } /// /// Check if a enum value represents a modifier key. /// /// The key enum value you want to check. /// true if represents a modifier key, else false. /// /// Modifier keys are any keys you can hold down to modify the output of other keys pressed simultaneously, /// such as the "shift" or "control" keys. /// public static bool IsModifierKey(this Key key) { switch (key) { case Key.LeftAlt: case Key.RightAlt: case Key.LeftShift: case Key.RightShift: case Key.LeftMeta: case Key.RightMeta: case Key.LeftCtrl: case Key.RightCtrl: return true; } return false; } ////REVIEW: Is this a good idea? Ultimately it's up to any one keyboard layout to define this however it wants. /// /// Check if a enum value represents key generating text input. /// /// The key enum value you want to check. /// true if represents a key generating non-whitespace text input, else false. public static bool IsTextInputKey(this Key key) { switch (key) { case Key.LeftShift: case Key.RightShift: case Key.LeftAlt: case Key.RightAlt: case Key.LeftCtrl: case Key.RightCtrl: case Key.LeftMeta: case Key.RightMeta: case Key.ContextMenu: case Key.Escape: case Key.LeftArrow: case Key.RightArrow: case Key.UpArrow: case Key.DownArrow: case Key.Backspace: case Key.PageDown: case Key.PageUp: case Key.Home: case Key.End: case Key.Insert: case Key.Delete: case Key.CapsLock: case Key.NumLock: case Key.PrintScreen: case Key.ScrollLock: case Key.Pause: case Key.None: case Key.Space: case Key.Enter: case Key.Tab: case Key.NumpadEnter: case Key.F1: case Key.F2: case Key.F3: case Key.F4: case Key.F5: case Key.F6: case Key.F7: case Key.F8: case Key.F9: case Key.F10: case Key.F11: case Key.F12: case Key.OEM1: case Key.OEM2: case Key.OEM3: case Key.OEM4: case Key.OEM5: case Key.IMESelected: return false; } return true; } } }