Skip to main content

KeyPress struct

Namespace: Arlecchino.Input · Assembly: Arlecchino.Core

One key press, as the framework hands it to a view. It is ConsoleKeyInfo with room for Command, which that type has nowhere to put.

public readonly struct KeyPress : IEquatable<KeyPress>

Implements IEquatable<T><KeyPress>

Constructors

MemberSummary
KeyPress(char)Creates a press the terminal reported as a character with no key behind it.
KeyPress(ConsoleKey, KeyModifiers, char)One key press, as the framework hands it to a view. It is ConsoleKeyInfo with room for Command, which that type has nowhere to put.

Properties

MemberSummary
CharacterThe character it typed, or '\0' for keys that type nothing.
IsNothingWhether this is the press a terminal hands back when there was nothing to read — no key, no character, nothing held.
KeyThe key itself, or default when the terminal named no key and only sent a character.
ModifiersWhat was held with it.

Methods

MemberSummary
Deconstruct(out ConsoleKey, out KeyModifiers, out char)
From(ConsoleKeyInfo)Takes over what a console reported. Nothing is lost: the console cannot report Command in the first place, which is the whole reason this type exists.

Constructors in detail

KeyPress(char)

public KeyPress(char character);

Creates a press the terminal reported as a character with no key behind it.

Parameters

NameTypeDescription
charactercharThe character that arrived.

KeyPress(ConsoleKey, KeyModifiers, char)

public KeyPress(ConsoleKey Key, KeyModifiers Modifiers = None, char Character = '\0');

One key press, as the framework hands it to a view. It is ConsoleKeyInfo with room for Command, which that type has nowhere to put.

Parameters

NameTypeDescription
KeyConsoleKeyThe key itself, or default when the terminal named no key and only sent a character.
ModifiersKeyModifiersWhat was held with it.
CharactercharThe character it typed, or '\0' for keys that type nothing.

Properties in detail

Character

public char Character { get; init; }

The character it typed, or '\0' for keys that type nothing.

Type char

IsNothing

public bool IsNothing { get; }

Whether this is the press a terminal hands back when there was nothing to read — no key, no character, nothing held.

Type bool

Key

public ConsoleKey Key { get; init; }

The key itself, or default when the terminal named no key and only sent a character.

Type ConsoleKey

Modifiers

public KeyModifiers Modifiers { get; init; }

What was held with it.

Type KeyModifiers

Methods in detail

Deconstruct(out ConsoleKey, out KeyModifiers, out char)

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

Parameters

NameTypeDescription
KeyConsoleKey
ModifiersKeyModifiers
Characterchar

From(ConsoleKeyInfo)

public static KeyPress From(ConsoleKeyInfo key);

Takes over what a console reported. Nothing is lost: the console cannot report Command in the first place, which is the whole reason this type exists.

Parameters

NameTypeDescription
keyConsoleKeyInfoWhat the console handed over.

Returns KeyPress — The same press.