Skip to main content

KeyStroke struct

Namespace: Arlecchino.Input · Assembly: Arlecchino.Core

One key and the modifiers held with it, which is the smallest thing a binding can be made of. A KeyBinding is one of these plus its alternatives and its finishing key.

public readonly struct KeyStroke : IEquatable<KeyStroke>

Implements IEquatable<T><KeyStroke>

Constructors

MemberSummary
KeyStroke(char)A stroke on a character rather than on a key, which is the only way to name punctuation. It answers on every layout that can type that character, whatever the keyboard does to produce it.
KeyStroke(ConsoleKey, KeyModifiers)One key and the modifiers held with it, which is the smallest thing a binding can be made of. A KeyBinding is one of these plus its alternatives and its finishing key.

Properties

MemberSummary
CharacterThe character this stroke answers to, or '\0' when it is a stroke on a key.
IsNoneWhether the stroke is unset and therefore stands for no key at all.
KeyThe key itself.
ModifiersModifiers that must be held, exactly.

Methods

MemberSummary
Deconstruct(out ConsoleKey, out KeyModifiers)
Matches(KeyPress)Whether a key press is this stroke, by the key where one was reported and by the character otherwise. A key that answers to two names matches under either, and a stroke on a character forgives Shift.
Replacing(KeyModifiers, KeyModifiers)The same stroke with one modifier put in place of another.
ToString()How the stroke is shown to the user — Ctrl+S, Alt+←, Esc. The palette and the hints box display this, so a rebound key relabels itself everywhere.

Constructors in detail

KeyStroke(char)

public KeyStroke(char character);

A stroke on a character rather than on a key, which is the only way to name punctuation. It answers on every layout that can type that character, whatever the keyboard does to produce it.

Parameters

NameTypeDescription
charactercharThe character to answer to.

KeyStroke(ConsoleKey, KeyModifiers)

public KeyStroke(ConsoleKey Key, KeyModifiers Modifiers = None);

One key and the modifiers held with it, which is the smallest thing a binding can be made of. A KeyBinding is one of these plus its alternatives and its finishing key.

Parameters

NameTypeDescription
KeyConsoleKeyThe key itself.
ModifiersKeyModifiersModifiers that must be held, exactly.

Properties in detail

Character

public char Character { get; }

The character this stroke answers to, or '\0' when it is a stroke on a key.

Type char

IsNone

public bool IsNone { get; }

Whether the stroke is unset and therefore stands for no key at all.

Type bool

Key

public ConsoleKey Key { get; init; }

The key itself.

Type ConsoleKey

Modifiers

public KeyModifiers Modifiers { get; init; }

Modifiers that must be held, exactly.

Type KeyModifiers

Methods in detail

Deconstruct(out ConsoleKey, out KeyModifiers)

public void Deconstruct(out ConsoleKey Key, out KeyModifiers Modifiers);

Parameters

NameTypeDescription
KeyConsoleKey
ModifiersKeyModifiers

Matches(KeyPress)

public bool Matches(KeyPress press);

Whether a key press is this stroke, by the key where one was reported and by the character otherwise. A key that answers to two names matches under either, and a stroke on a character forgives Shift.

Parameters

NameTypeDescription
pressKeyPressThe key that was pressed.

Returns booltrue when the press is this combination.

Replacing(KeyModifiers, KeyModifiers)

public KeyStroke Replacing(KeyModifiers from, KeyModifiers to);

The same stroke with one modifier put in place of another.

Parameters

NameTypeDescription
fromKeyModifiersThe modifier to take out.
toKeyModifiersThe modifier to put in its place.

Returns KeyStroke — The rewritten stroke, or this one when the modifier is not held.

ToString()

public override string ToString();

How the stroke is shown to the user — Ctrl+S, Alt+←, Esc. The palette and the hints box display this, so a rebound key relabels itself everywhere.

Returns string — The readable form, or an empty string when the stroke is unset.