Table of Contents

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

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?.

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.

KeyBindings

Provides a collection of Keys bound to Commands.

KeyChangedEventArgs

Event args for when a Key is changed from one value to a new value (e.g. in HotKeyChanged)

KeystrokeNavigatorEventArgs

Event arguments for the Terminal.Gui.Views.CollectionNavigatorBase.SearchStringChanged event.

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

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

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

Command

Actions which can be performed by a View.

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 IsBubblingUp and IsBubblingDown with 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.