#nullable enable namespace Terminal.Gui.App; public static partial class Application // Keyboard handling { /// /// Static reference to the current . /// public static IKeyboard Keyboard { get => ApplicationImpl.Instance.Keyboard; set => ApplicationImpl.Instance.Keyboard = value ?? throw new ArgumentNullException(nameof(value)); } /// /// Called when the user presses a key (by the ). Raises the cancelable /// event, then calls on all top level views, and finally /// if the key was not handled, invokes any Application-scoped . /// /// Can be used to simulate key press events. /// /// if the key was handled. public static bool RaiseKeyDownEvent (Key key) => Keyboard.RaiseKeyDownEvent (key); /// /// Invokes any commands bound at the Application-level to . /// /// /// /// if no command was found; input processing should continue. /// if the command was invoked and was not handled (or cancelled); input processing should continue. /// if the command was invoked the command was handled (or cancelled); input processing should stop. /// public static bool? InvokeCommandsBoundToKey (Key key) => Keyboard.InvokeCommandsBoundToKey (key); /// /// Invokes an Application-bound command. /// /// The Command to invoke /// The Application-bound Key that was pressed. /// Describes the binding. /// /// if no command was found; input processing should continue. /// if the command was invoked and was not handled (or cancelled); input processing should continue. /// if the command was invoked the command was handled (or cancelled); input processing should stop. /// /// public static bool? InvokeCommand (Command command, Key key, KeyBinding binding) => Keyboard.InvokeCommand (command, key, binding); /// /// Raised when the user presses a key. /// /// Set to to indicate the key was handled and to prevent /// additional processing. /// /// /// /// All drivers support firing the event. Some drivers (Unix) do not support firing the /// and events. /// Fired after and before . /// public static event EventHandler? KeyDown { add => Keyboard.KeyDown += value; remove => Keyboard.KeyDown -= value; } /// /// Called when the user releases a key (by the ). Raises the cancelable /// /// event /// then calls on all top level views. Called after . /// /// Can be used to simulate key release events. /// /// if the key was handled. public static bool RaiseKeyUpEvent (Key key) => Keyboard.RaiseKeyUpEvent (key); /// Gets the Application-scoped key bindings. public static KeyBindings KeyBindings => Keyboard.KeyBindings; internal static void AddKeyBindings () { if (Keyboard is KeyboardImpl keyboard) { keyboard.AddKeyBindings (); } } }