46 lines
780 B
Dart
46 lines
780 B
Dart
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);
|
|
|
|
String? text() => _text;
|
|
}
|
|
|
|
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,
|
|
};
|