Namespace Terminal.Gui.Input
Keyboard, mouse, and command processing.
The Input namespace provides input handling for keyboard events, mouse interactions, and the command execution framework.
Key Types
- Key - Keyboard input with modifier support (Ctrl, Alt, Shift)
- Mouse - Mouse event data (position, buttons, modifiers)
- Command - Standard application commands enum
- KeyBinding / MouseBinding - Associates input with commands
- Responder - Base class for input handling
Command Pattern
Views handle input through commands:
// 1. Add command handlers
AddCommand (Command.Accept, ctx => { /* handle */ return true; });
AddCommand (Command.Cancel, ctx => { /* handle */ return true; });
// 2. Bind keys to commands
KeyBindings.Add (Key.Enter, Command.Accept);
KeyBindings.Add (Key.Esc, Command.Cancel);
// 3. Bind mouse to commands
MouseBindings.Add (MouseFlags.Button1Clicked, Command.Accept);
Key Modifiers
Key.A.WithCtrl // Ctrl+A
Key.A.WithAlt // Alt+A
Key.A.WithShift // Shift+A (uppercase)
Key.F1.WithCtrl.WithShift // Ctrl+Shift+F1
See Also
Classes
- Bind
Provides ergonomic factory methods for creating PlatformKeyBinding instances.
- BindMouse
Provides ergonomic factory methods for creating PlatformMouseBinding instances.
- CommandBindingsBase<TEvent, TBinding>
Abstract class for KeyBindings and MouseBindings. This class is thread-safe for all public operations.
- CommandBridge
Bridges command routing across non-containment boundaries (e.g., between a MenuBarItem and its PopoverMenu, which is registered with Application.Popover rather than the SuperView hierarchy).
- CommandContextExtensions
Extension methods for ICommandContext.
- CommandEventArgs
Event arguments for Command events. Set Handled to true to indicate a command was handled.
- CommandOutcomeExtensions
Provides extension methods for converting between CommandOutcome and
bool?.
- CommandRoutingExtensions
Extension methods for the CommandRouting enum type.
- GrabMouseEventArgs
Provides data for mouse grab-related events (GrabbingMouse and UnGrabbingMouse).
- Key
Provides an abstraction for common keyboard operations and state. Used for processing keyboard input and raising keyboard events.
- KeyChangedEventArgs
Event args for when a Key is changed from one value to a new value (e.g. in HotKeyChanged)
- KeyEventTypeExtensions
Extension methods for the KeyEventType enum type.
- KeystrokeNavigatorEventArgs
Event arguments for the Terminal.Gui.Views.CollectionNavigatorBase.SearchStringChanged event.
- ModifierKeyExtensions
Extension methods for the ModifierKey enum type.
- Mouse
Provides an abstraction for common mouse operations and state. Represents a mouse event, including position, button state, and other flags.
- MouseBindings
Provides a collection of MouseBinding objects bound to a combination of MouseFlags.
- MouseFlagsChangedEventArgs
Args for events that describe a change in MouseFlags
- MouseFlagsExtensions
Extension methods for the MouseFlags enum type.
- PasteEventArgs
Event arguments for the application-level Paste event. Carries the raw payload delivered by the terminal's bracketed-paste mode, before any view-level sanitization. Set Handled to true to stop the paste from being dispatched to the focused view.
- PastedEventArgs
Event arguments for the Pasted event raised after the default Paste handler has consumed a paste. Observation only — handlers cannot cancel or alter what has already been inserted.
- PastingEventArgs
Event arguments for the cancellable Pasting event raised by the default Paste handler. Text is mutable so subscribers can normalize or filter the payload before the view inserts it; set Handled to true to cancel the paste.
- PlatformKeyBinding
Defines the keys for a single command, optionally varying by platform. Keys are additive — for example, on Linux both All and Linux keys apply.
- PlatformMouseBinding
Defines the mouse flags for a single command, optionally varying by platform. Mouse flags are additive — for example, on Linux both All and Linux flags apply.
Structs
- CommandBinding
A generic command binding used for programmatic command invocations or when a specific binding type is not needed.
- CommandContext
Provides context for a Command invocation.
- KeyBinding
Provides a collection of Command objects stored in KeyBindings. Carried as context in command invocations (see CommandContext).
- MouseBinding
Provides a collection of Command objects stored in MouseBindings. Carried as context in command invocations (see CommandContext).
Interfaces
- IAcceptTarget
Interface for views that handle Accept as terminal destinations. Views implementing this interface can bubble their Accept commands up to their SuperView or be treated as the default accept target depending on IsDefault.
- ICommandBinding
Describes command binding. Used to bind a set of Command objects to a specific user event and passed as part of command invocations (see CommandContext). Bindings are immutable.
- ICommandContext
Describes the context in which a Command is being invoked. When a Command is invoked via InvokeCommand(Command) a context object is passed to Command handlers as an ICommandContext reference.
Enums
- CommandOutcome
Describes the outcome of a Command invocation, replacing the three-valued
bool?(null = not found, false = not handled, true = handled).
- CommandRouting
Describes how a Command is being routed through the view hierarchy. Replaces the ad-hoc boolean flags
IsBubblingUpandIsBubblingDownwith a single discriminated enum.
- KeyEventType
Describes the type of keyboard event: press, release, or repeat.
- ModifierKey
Identifies a specific modifier key for standalone modifier key events.
- MouseFlags
Mouse flags reported in Mouse.