Pattern for matching keyboard events. More...
Public Member Functions | |
| bool | Matches (KeyMsg msg) |
| Returns true if msg matches this pattern. | |
Static Public Member Functions | |
| static KeyPattern | Of (ConsoleKey key) |
| Match the key with any modifier combination. | |
| static KeyPattern | OfChar (char c) |
Match a printable character, whatever key produced it — the layout-independent way to bind ?, /, or a case-sensitive letter. | |
| static KeyPattern | Plain (ConsoleKey key) |
| Match the key with no modifiers pressed. | |
| static KeyPattern | WithAlt (ConsoleKey key) |
| Match Alt + key (Shift and Ctrl are wildcards). | |
| static KeyPattern | WithCtrl (ConsoleKey key) |
| Match Ctrl + key (Shift and Alt are wildcards). | |
| static KeyPattern | WithShift (ConsoleKey key) |
| Match Shift + key (Alt and Ctrl are wildcards). | |
Pattern for matching keyboard events.
Every field is optional, and null means "wildcard" — that field is not consulted. A pattern matches a KeyMsg when all of its non-null fields agree with it.
There are two ways to name a key. Of(ConsoleKey) matches the ConsoleKey, which is right for keys that produce no character — arrows, Enter, Tab, function keys. OfChar(char) matches the character the terminal actually produced, which is right for printable bindings because it is independent of keyboard layout: ? sits on a different physical key on a German or French layout, but it is still '?'.
A pattern with no field set — default(KeyPattern) — matches every key event. That is usable as a catch-all at the end of a KeyMap, but because this is a struct, a default reached by accident will silently swallow all input.
| bool ConsoleForge.Core.KeyPattern.Matches | ( | KeyMsg | msg | ) |
Returns true if msg matches this pattern.
Null fields are skipped, so a pattern constrains only what it names.
|
static |
Match a printable character, whatever key produced it — the layout-independent way to bind ?, /, or a case-sensitive letter.
Ctrl and Alt must be absent: Ctrl+letter arrives as a control character rather than the letter, and Alt+key is a distinct binding that would otherwise match here, since the Alt path preserves KeyMsg.Character. Shift is deliberately left a wildcard — it has already been consumed producing the glyph, so requiring it would re-introduce the layout assumption this factory removes.
Control keys carry characters too (Enter is '\r', Tab '\t', Space ' '), so prefer Of(ConsoleKey) for those.