dartterm/lib/input.dart

46 lines
782 B
Dart
Raw Permalink Normal View History

2023-09-10 03:26:30 +00:00
import 'package:dartterm/terminal.dart';
import 'package:flutter/services.dart';
abstract class Input {
const Input();
}
class Click extends Input {
final Button button;
final int x, y;
const Click(this.button, this.x, this.y);
}
class Keystroke extends Input {
final Key? key;
final String? _text;
const Keystroke(this.key, this._text);
2023-09-21 03:56:30 +00:00
String? get text => _text;
2023-09-10 03:26:30 +00:00
}
enum Button { left, right }
enum Key { space }
void startListening() {
ServicesBinding.instance.keyboard.addHandler(_onKey);
}
bool _onKey(KeyEvent event) {
if (event is KeyDownEvent) {
final dartKey = event.logicalKey.keyLabel;
final realKey = _keys[dartKey];
notifyInput(Keystroke(realKey, event.character));
}
return false;
}
final _keys = {
" ": Key.space,
};