Key class

Represents a parsed keyboard input event.

Contains the type of key, any character data, and modifier state.

Example

// Regular character
final a = Key(KeyType.runes, runes: [0x61]); // 'a'

// Arrow key with modifier
final ctrlUp = Key(KeyType.up, ctrl: true);

// Check modifiers
if (key.hasModifier) { ... }
if (key.ctrl && key.type == KeyType.runes) { ... }
Available extensions

Constructors

Key(KeyType type, {List<int> runes = const [], bool ctrl = false, bool alt = false, bool shift = false, bool isRelease = false, bool isRepeat = false})
Creates a key event.
const
Key.char(String char, {bool ctrl = false, bool alt = false, bool shift = false})
Creates a key from a single character.
factory
Key.fromRune(int rune, {bool ctrl = false, bool alt = false, bool shift = false})
Creates a key from a single rune.
factory

Properties

alt bool
Whether the Alt/Option key was held.
final
char String?
Returns the character if this is a single character key, or null.
no setter
ctrl bool
Whether the Control key was held.
final
hashCode int
The hash code for this object.
no setteroverride
hasModifier bool
Whether any modifier key is held.
no setter
isAccept bool
Whether this key should be treated as an “accept/select/confirm” action.
no setter
isArrow bool
Whether this is an arrow key.
no setter
isBackspace bool
Whether this is the Backspace key.
no setter
isCtrlC bool
Whether this is Ctrl+C.
no setter
isCtrlChar bool
Whether this is a control character (Ctrl+letter).
no setter
isCtrlD bool
Whether this is Ctrl+D.
no setter
isCtrlZ bool
Whether this is Ctrl+Z.
no setter
isDelete bool
Whether this is the Delete key.
no setter
isEnter bool
Whether this is the Enter key (with or without modifiers).
no setter
isEnterLike bool
Whether this key represents Enter/Return for input handling.
no setter
isEscape bool
Whether this is the Escape key.
no setter
isFunctionKey bool
Whether this is a function key (F1-F20).
no setter
isNavigation bool
Whether this is a navigation key (arrows, home, end, page up/down).
no setter
isPrintable bool
Whether this is a printable character.
no setter
isRelease bool
Whether this is a key release event.
final
isRepeat bool
Whether this is a key repeat event.
final
isRune bool
Whether this is a regular character key (runes type with content).
no setter
isSpaceLike bool
Whether this key represents a space press for input handling.
no setter
isTab bool
Whether this is the Tab key (with or without modifiers).
no setter
rune int
Returns the first rune if available, or -1.
no setter
runes List<int>
The Unicode code points for character input.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shift bool
Whether the Shift key was held.
final
type KeyType
The type of key.
final

Methods

copyWith({KeyType? type, List<int>? runes, bool? ctrl, bool? alt, bool? shift, bool? isRelease, bool? isRepeat}) Key
Creates a copy of this key with the given fields replaced.
isChar(String c, {bool requireNoModifiers = true, bool caseSensitive = true}) bool
Returns whether this key represents the given character.
isRuneValue(int codePoint, {bool requireNoModifiers = true}) bool
Returns whether this key represents exactly the given code point.
matches(List<KeyBinding> bindings) bool

Available on Key, provided by the KeyMatchExtension extension

Returns true if this key matches any of the given bindings.
matchesSingle(KeyBinding binding) bool

Available on Key, provided by the KeyMatchExtension extension

Returns true if this key matches the given binding.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override