keyboard works

This commit is contained in:
open-trade 2020-11-25 16:28:46 +08:00
parent b04f90ef67
commit 114f03f00c
2 changed files with 206 additions and 72 deletions

View File

@ -395,6 +395,10 @@ class FFI {
static F4 _freeRgba; static F4 _freeRgba;
static F5 _getRgba; static F5 _getRgba;
static Pointer<RgbaFrame> _lastRgbaFrame; static Pointer<RgbaFrame> _lastRgbaFrame;
static var shift = false;
static var ctrl = false;
static var alt = false;
static var command = false;
static final imageModel = ImageModel(); static final imageModel = ImageModel();
static final ffiModel = FfiModel(); static final ffiModel = FfiModel();
static final cursorModel = CursorModel(); static final cursorModel = CursorModel();
@ -405,21 +409,38 @@ class FFI {
} }
static void tap() { static void tap() {
FFI.sendMouse('down', 'left'); sendMouse('down', 'left');
FFI.sendMouse('up', 'left'); sendMouse('up', 'left');
}
static void resetModifiers() {
shift = ctrl = alt = command = false;
}
static Map<String, String> modify(Map<String, String> evt) {
if (ctrl) evt['ctrl'] = 'true';
if (shift) evt['shift'] = 'true';
if (alt) evt['alt'] = 'true';
if (command) evt['command'] = 'true';
return evt;
} }
static void sendMouse(String type, String buttons) { static void sendMouse(String type, String buttons) {
if (!FFI.ffiModel.keyboard()) return; if (!ffiModel.keyboard()) return;
FFI.setByName( setByName(
'send_mouse', json.encode({'type': type, 'buttons': buttons})); 'send_mouse', json.encode(modify({'type': type, 'buttons': buttons})));
}
static void inputKey(String name) {
if (!ffiModel.keyboard()) return;
setByName('input_key', json.encode(modify({'name': name})));
} }
static void moveMouse(double x, double y) { static void moveMouse(double x, double y) {
if (!FFI.ffiModel.keyboard()) return; if (!ffiModel.keyboard()) return;
var x2 = x.toInt(); var x2 = x.toInt();
var y2 = y.toInt(); var y2 = y.toInt();
FFI.setByName('send_mouse', json.encode({'x': '$x2', 'y': '$y2'})); setByName('send_mouse', json.encode(modify({'x': '$x2', 'y': '$y2'})));
} }
static List<Peer> peers() { static List<Peer> peers() {
@ -475,10 +496,11 @@ class FFI {
static void close() { static void close() {
setByName('close', ''); setByName('close', '');
FFI.imageModel.update(null); imageModel.update(null);
FFI.cursorModel.clear(); cursorModel.clear();
FFI.ffiModel.clear(); ffiModel.clear();
FFI.canvasModel.clear(); canvasModel.clear();
resetModifiers();
} }
static void setByName(String name, [String value = '']) { static void setByName(String name, [String value = '']) {

View File

@ -22,17 +22,17 @@ class _RemotePageState extends State<RemotePage> {
Timer _interval; Timer _interval;
bool _showBar = true; bool _showBar = true;
double _bottom = 0; double _bottom = 0;
String _value = '';
double _xOffset = 0; double _xOffset = 0;
double _yOffset = 0; double _yOffset = 0;
double _scale = 1; double _scale = 1;
bool _mouseTools = false; bool _mouseTools = false;
var _shift = false;
var _ctrl = false;
var _alt = false;
var _command = false;
var _drag = false; var _drag = false;
var _right = false; var _right = false;
var _scroll = false; var _scroll = false;
var _arrows = false;
var _more = false;
var _fn = false;
final FocusNode _focusNode = FocusNode(); final FocusNode _focusNode = FocusNode();
@override @override
@ -59,12 +59,19 @@ class _RemotePageState extends State<RemotePage> {
Wakelock.disable(); Wakelock.disable();
} }
void resetTool() {
_scroll = _drag = _right = false;
FFI.resetModifiers();
}
void interval() { void interval() {
var v = MediaQuery.of(context).viewInsets.bottom; var v = MediaQuery.of(context).viewInsets.bottom;
if (v != _bottom) { if (v != _bottom) {
resetTool();
_value = '';
setState(() { setState(() {
_bottom = v; _bottom = v;
if (v < 80) { if (v < 100) {
SystemChrome.setEnabledSystemUIOverlays([]); SystemChrome.setEnabledSystemUIOverlays([]);
} }
}); });
@ -147,8 +154,7 @@ class _RemotePageState extends State<RemotePage> {
onPressed: () { onPressed: () {
setState(() { setState(() {
_mouseTools = !_mouseTools; _mouseTools = !_mouseTools;
_command = _ctrl = _shift = resetTool();
_alt = _scroll = _drag = _right = false;
}); });
}, },
)), )),
@ -214,7 +220,17 @@ class _RemotePageState extends State<RemotePage> {
focusNode: _focusNode, focusNode: _focusNode,
maxLines: null, maxLines: null,
keyboardType: TextInputType.multiline, keyboardType: TextInputType.multiline,
onChanged: (x) => print('$x'), onChanged: (x) {
var char = x[x.length - 1];
if (x.length < _value.length) {
char = 'VK_BACK';
} else if (char == '\n') {
char = 'VK_RETURN';
}
if (char != '' && char != null)
FFI.inputKey(char);
_value = x;
},
), ),
), ),
])), ])),
@ -227,11 +243,12 @@ class _RemotePageState extends State<RemotePage> {
} }
Widget getHelpTools() { Widget getHelpTools() {
if (!_mouseTools) { final keyboard = _bottom >= 100;
if (!_mouseTools && !keyboard) {
return SizedBox(); return SizedBox();
} }
var textStyle = TextStyle(color: Colors.white, fontSize: 11); var wrap =
var wrap = (String text, void Function() onPressed, [bool active]) { (String text, void Function() onPressed, [bool active, IconData icon]) {
return ButtonTheme( return ButtonTheme(
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
vertical: 6, horizontal: 12), //adds padding inside the button vertical: 6, horizontal: 12), //adds padding inside the button
@ -244,20 +261,13 @@ class _RemotePageState extends State<RemotePage> {
borderRadius: BorderRadius.circular(5.0), borderRadius: BorderRadius.circular(5.0),
), ),
color: active == true ? MyTheme.accent50 : null, color: active == true ? MyTheme.accent50 : null,
child: Text(text, style: textStyle), child: icon != null
? Icon(icon, color: Colors.white)
: Text(text,
style: TextStyle(color: Colors.white, fontSize: 11)),
onPressed: onPressed)); onPressed: onPressed));
}; };
return Stack(children: [ final mouse = <Widget>[
SizedBox(
height: 80,
child: Container(child: null, color: Color(0x66000000)),
),
Container(
padding: const EdgeInsets.only(top: 20, left: 8, right: 8),
child: Wrap(
spacing: 5,
runSpacing: 5,
children: [
wrap('Drag', () { wrap('Drag', () {
setState(() { setState(() {
_drag = !_drag; _drag = !_drag;
@ -284,22 +294,124 @@ class _RemotePageState extends State<RemotePage> {
_drag = false; _drag = false;
} }
}); });
}, _right), }, _right)
];
final modifiers = <Widget>[
wrap('Ctrl', () { wrap('Ctrl', () {
setState(() => _ctrl = !_ctrl); setState(() => FFI.ctrl = !FFI.ctrl);
}, _ctrl), }, FFI.ctrl),
wrap('Alt', () { wrap('Alt', () {
setState(() => _alt = !_alt); setState(() => FFI.alt = !FFI.alt);
}, _alt), }, FFI.alt),
wrap('Shift', () { wrap('Shift', () {
setState(() => _shift = !_shift); setState(() => FFI.shift = !FFI.shift);
}, _shift), }, FFI.shift),
wrap('Command', () { wrap('Command', () {
setState(() => _command = !_command); setState(() => FFI.command = !FFI.command);
}, _command), }, FFI.command),
], ];
)) final keys = <Widget>[
]); wrap(
'Arrows',
() => setState(() {
setState(() {
_arrows = !_arrows;
if (_arrows) {
_fn = false;
_more = false;
}
});
}),
_arrows),
wrap(
'Fn',
() => setState(
() {
_fn = !_fn;
if (_fn) {
_arrows = false;
_more = false;
}
},
),
_fn),
wrap(
'More',
() => setState(
() {
_more = !_more;
if (_more) {
_arrows = false;
_fn = false;
}
},
),
_more),
];
final arrows = <Widget>[
SizedBox(width: 9999),
wrap('', () {
FFI.inputKey('VK_LEFT');
}, false, Icons.keyboard_arrow_left),
wrap('', () {
FFI.inputKey('VK_UP');
}, false, Icons.keyboard_arrow_up),
wrap('', () {
FFI.inputKey('VK_DOWN');
}, false, Icons.keyboard_arrow_down),
wrap('', () {
FFI.inputKey('VK_RIGHT');
}, false, Icons.keyboard_arrow_right),
];
final fn = <Widget>[
SizedBox(width: 9999),
];
for (var i = 1; i <= 12; ++i) {
final name = 'F' + i.toString();
fn.add(wrap(name, () {
FFI.inputKey('VK_' + name);
}));
}
final more = <Widget>[
SizedBox(width: 9999),
wrap('Esc', () {
FFI.inputKey('VK_ESCAPE');
}),
wrap('Tab', () {
FFI.inputKey('VK_TAB');
}),
wrap('Home', () {
FFI.inputKey('VK_HOME');
}),
wrap('End', () {
FFI.inputKey('VK_END');
}),
wrap('Del', () {
FFI.inputKey('VK_DELETE');
}),
wrap('PeUp', () {
FFI.inputKey('VK_PRIOR');
}),
wrap('PgDown', () {
FFI.inputKey('VK_NEXT');
}),
];
return Container(
color: Color(0x77000000),
padding: EdgeInsets.only(
top: keyboard ? 24 : 4, left: 8, right: 8, bottom: 8),
child: Wrap(
spacing: 4,
runSpacing: 4,
children: <Widget>[SizedBox(width: 9999)] +
(keyboard
? modifiers +
keys +
(_arrows ? arrows : []) +
(_fn ? fn : []) +
(_more ? more : [])
: mouse + modifiers),
));
} }
} }
@ -514,7 +626,7 @@ void showActions(BuildContext context) {
child: Text('Insert Ctrl + Alt + Del'), value: 'cad'), child: Text('Insert Ctrl + Alt + Del'), value: 'cad'),
PopupMenuItem<String>(child: Text('Insert Lock'), value: 'lock'), PopupMenuItem<String>(child: Text('Insert Lock'), value: 'lock'),
], ],
elevation: 8.0, elevation: 8,
); );
if (value == 'cad') { if (value == 'cad') {
FFI.setByName('ctrl_alt_del'); FFI.setByName('ctrl_alt_del');