Namespace Terminal.Gui.Input
The Input
namespace provides comprehensive input handling for keyboard, mouse, and command processing.
Terminal.Gui.Input contains the input processing system for Terminal.Gui applications, including keyboard event handling, mouse interaction, and the command execution framework. This namespace defines the core input primitives and event structures used throughout the framework.
The input system provides both low-level input events and high-level command abstractions, enabling applications to handle everything from basic key presses to complex gesture recognition and command routing.
Key Components
- Key: Represents keyboard input with modifier support
- MouseEventArgs: Comprehensive mouse event information
- Command: Enumeration of standard application commands
- KeyBinding: Associates keys with commands
- MouseBinding: Associates mouse events with commands
Example Usage
// First, add command handlers
AddCommand(Command.Up, commandContext => Move(commandContext, -16));
AddCommand(Command.Down, commandContext => Move(commandContext, 16));
AddCommand(Command.Accept, HandleAcceptCommand);
// Then bind keys to commands
KeyBindings.Add(Key.CursorUp, Command.Up);
KeyBindings.Add(Key.CursorDown, Command.Down);
KeyBindings.Add(Key.Enter, Command.Accept);
// Then bind mouse events to commands
MouseBindings.Add(MouseFlags.Button1DoubleClicked, Command.Accept);
MouseBindings.Add(MouseFlags.WheeledDown, Command.ScrollDown);
MouseBindings.ReplaceCommands(MouseFlags.Button3Clicked, Command.Context);
Deep Dives
- Keyboard Input - Comprehensive keyboard input handling
- Mouse Input - Comprehensive mouse input handling
- Commands - Command execution framework details
Classes
- CommandEventArgs
Event arguments for Command events. Set Handled to true to indicate a command was handled.
- GrabMouseEventArgs
Args GrabMouse related events.
- InputBindings<TEvent, TBinding>
Abstract class for KeyBindings and MouseBindings.
- 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)
- KeystrokeNavigatorEventArgs
Event arguments for the Terminal.Gui.Views.CollectionNavigatorBase.SearchStringChanged event.
- MouseBindings
Provides a collection of MouseBinding objects bound to a combination of MouseFlags.
- MouseEventArgs
Specifies the event arguments for MouseEventArgs. This is a higher-level construct than the wrapped MouseEventArgs class and is used for the events defined on View and subclasses of View (e.g. MouseEnter and MouseClick).
- MouseFlagsChangedEventArgs
Args for events that describe a change in MouseFlags
Structs
- CommandContext<TBinding>
Provides context for a Command invocation.
- KeyBinding
Provides a collection of Command objects stored in KeyBindings.
- MouseBinding
Provides a collection of MouseFlags bound to Commands.
Interfaces
- ICommandContext
Describes the context in which a Command is being invoked. CommandContext<TBinding> inherits from this interface. When a Command is invoked, a context object is passed to Command handlers as an ICommandContext reference.
- IInputBinding
Describes an input binding. Used to bind a set of Command objects to a specific input event.
Enums
- MouseFlags
Mouse flags reported in MouseEventArgs.