mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-05-08 23:28:09 +03:00
feat(keyboard): shortcuts, debug web
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -15,7 +15,9 @@ import 'package:get/get.dart';
|
||||
|
||||
import '../../models/model.dart';
|
||||
import '../../models/platform_model.dart';
|
||||
import '../../models/shortcut_model.dart';
|
||||
import '../../models/state_model.dart';
|
||||
import '../common/widgets/keyboard_shortcuts/shortcut_utils.dart';
|
||||
import 'input_modifier_utils.dart';
|
||||
import 'relative_mouse_model.dart';
|
||||
import '../common.dart';
|
||||
@@ -826,6 +828,9 @@ class InputModel {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
}
|
||||
if (_tryDispatchWebFlutterShortcut(e)) {
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (isWindows || isLinux) {
|
||||
// Ignore meta keys. Because flutter window will loose focus if meta key is pressed.
|
||||
if (e.physicalKey == PhysicalKeyboardKey.metaLeft ||
|
||||
@@ -920,6 +925,53 @@ class InputModel {
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
bool _tryDispatchWebFlutterShortcut(KeyEvent e) {
|
||||
if (!isWeb || !isInputSourceFlutter) return false;
|
||||
if (e is! KeyDownEvent && e is! KeyRepeatEvent) return false;
|
||||
if (!ShortcutModel.isEnabled() || ShortcutModel.isPassThrough()) {
|
||||
return false;
|
||||
}
|
||||
final keyName = logicalKeyName(e.logicalKey);
|
||||
if (keyName == null) return false;
|
||||
final mods = canonicalShortcutModsForSave(_webFlutterShortcutMods());
|
||||
final action = _matchWebFlutterShortcut(keyName, mods);
|
||||
if (action == null) return false;
|
||||
if (e is KeyDownEvent) {
|
||||
parent.target?.shortcutModel.onTriggered(action);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Set<String> _webFlutterShortcutMods() {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
final mods = <String>{};
|
||||
if (isMacOS || isIOS || isWebOnMacOs) {
|
||||
if (keyboard.isMetaPressed) mods.add('primary');
|
||||
if (keyboard.isControlPressed) mods.add('ctrl');
|
||||
} else if (keyboard.isControlPressed) {
|
||||
mods.add('primary');
|
||||
}
|
||||
if (keyboard.isAltPressed) mods.add('alt');
|
||||
if (keyboard.isShiftPressed) mods.add('shift');
|
||||
return mods;
|
||||
}
|
||||
|
||||
String? _matchWebFlutterShortcut(String keyName, List<String> mods) {
|
||||
for (final binding in ShortcutModel.readBindings()) {
|
||||
final action = binding['action'];
|
||||
final key = binding['key'];
|
||||
final bindingMods =
|
||||
canonicalShortcutModsForSave(shortcutModSetFrom(binding['mods']));
|
||||
if (action is String &&
|
||||
key == keyName &&
|
||||
bindingMods.isNotEmpty &&
|
||||
listEquals(bindingMods, mods)) {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Send Key Event
|
||||
void newKeyboardMode(
|
||||
String character, int usbHid, bool down, bool iosCapsLock) {
|
||||
|
||||
Reference in New Issue
Block a user