BufferedKeys class abstract
A minimal buffer interface for synchronously reading the state of keys.
When reading directly from the terminal using dart:io
, you can either:
- Block the program until a key is pressed (
stdin.readByteSync()
). - Capture event codes as they are received (
stdin.listen()
).
BufferedKeys provides a synchronous API for the state of key codes:
import 'dart:io' as io;
void main() async {
const frames = Duration(milliseconds: 1000 ~/ 60);
const qKey = 0x51;
final bufferedKeys = BufferedKeys.fromStream(io.stdin);
io.stdout.writeln('Press Q to exit.');
await for (final _ in Stream.periodic(frames)) {
if (bufferedKeys.isPressed(qKey)) {
break;
}
bufferedKeys.clear();
}
await bufferedKeys.close();
}
Constructors
- BufferedKeys()
-
const
-
BufferedKeys.fromBuffer(Set<
(int, int, int, int, int, int)> buffer) -
Creates a new buffered keys instance using the provided
buffer
.factory -
BufferedKeys.fromStream(Stream<
List< input)int> > -
Creates a new buffered keys instance from the provided
input
stream.factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isAnyPressed → bool
-
Returns whether any key code is currently pressed.
no setter
-
pressed
→ Iterable<
List< int> > -
All currently pressed key code combinations.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clear(
) → void - Clears the buffer of any key codes.
-
close(
) → Future< void> - Closes the buffered keys and releases any resources.
-
isPressed(
int code1, [int code2, int code3, int code4, int code5, int code6]) → bool - Returns whether the provided key code combination is currently pressed.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited