Table of Contents

Property HotKey

Namespace
Terminal.Gui.ViewBase
Assembly
Terminal.Gui.dll

HotKey

Gets or sets the hot key defined for this view. Pressing the hot key on the keyboard while this view has focus will invoke HotKey. By default, the HotKey is set to the first character of Text that is prefixed with HotKeySpecifier.

A HotKey is a keypress that causes a visible UI item to perform an action. For example, in a Dialog, with a Button with the text of "_Text" Alt+T will cause the button to gain focus and to raise its Accepting event. Or, in a Menu with "_File _Edit", Alt+F will select (show) the Strings.menuFile menu. If the Strings.menuFile menu has a sub-menu of Strings.cmdNew Alt+N or N will ONLY select the Strings.cmdNew sub-menu if the Strings.menuFile menu is already opened.

View subclasses can use AddCommand(Command, CommandImplementation) to define the behavior of the hot key.

public Key HotKey { get; set; }

Property Value

Key

Remarks

See ../docs/keyboard.md for an overview of Terminal.Gui keyboard APIs.

This is a helper API for configuring a key binding for the hot key. By default, this property is set whenever Text changes.

By default, when the Hot Key is set, key bindings are added for both the base key (e.g. D3) and the Alt-shifted key (e.g. D3. WithAlt). This behavior can be overriden by overriding AddKeyBindingsForHotKey(Key, Key, object?).

By default, when the HotKey is set to A through Z key bindings will be added for both the un-shifted and shifted versions. This means if the HotKey is A, key bindings for Key.A and Key.A.WithShift will be added. This behavior can be overriden by overriding AddKeyBindingsForHotKey(Key, Key, object?).

If the hot key is changed, the HotKeyChanged event is fired.

Set to Empty to clear the current hot key. If automatic assignment inserted the title specifier, clearing the hot key removes that marker through the normal TitleChanging and TitleChanged workflow. If a handler cancels the title change, the current title hotkey is retained.

When the superview has AssignHotKeys enabled, a programmatically set hot key takes precedence over a title specifier. If that key is already reserved, the first view keeps it and a later view uses a distinct available title character when possible. If no alternate title character is available, the programmatic key remains set but is not reserved. A conflicting title marker is repositioned through the normal title-changing workflow; cancellation keeps the title's current hotkey. Clearing the hot key releases its reservation but does not prevent a later title change or assignment pass from assigning one automatically. Set HotKeySpecifier to (Rune)0xffff to disable title-based assignment.

A subview with AssignHotKeys set to false is excluded from that automatic assignment. A programmatically set hot key and a specifier already present in Title are kept, and no specifier is inserted.