Skip to content

PasteFerry (隔空贴): clipboard and file sync across macOS, Windows and Linux. Direct-first, end-to-end encrypted. Optional official access: no server to host. Independent self-hosting remains available.

fix(ui): recognize quick paste digits without a scan code

baiyuze25f73acd30fe
diff --git a/ui/lib/picker/picker_view.dart b/ui/lib/picker/picker_view.dart
index 0c3abd3..8123c54 100644
--- a/ui/lib/picker/picker_view.dart
+++ b/ui/lib/picker/picker_view.dart
@@ -196,12 +196,19 @@ class _PickerViewState extends State<PickerView> {
return KeyEventResult.ignored;
}
+ /// 先按物理位置认(法语 AZERTY 等布局要按 Shift 才出数字),认不出再按逻辑按键:
+ /// 远程桌面、按键脚本这类模拟输入在 Windows 上可能不带扫描码,Flutter 就认不出物理按键。
static int? _digit(KeyEvent e) {
final u = e.physicalKey.usbHidUsage;
final one = PhysicalKeyboardKey.digit1.usbHidUsage;
if (u >= one && u <= PhysicalKeyboardKey.digit9.usbHidUsage) return 1 + u - one;
final pad = PhysicalKeyboardKey.numpad1.usbHidUsage;
if (u >= pad && u <= PhysicalKeyboardKey.numpad9.usbHidUsage) return 1 + u - pad;
+ final l = e.logicalKey.keyId;
+ final lone = LogicalKeyboardKey.digit1.keyId;
+ if (l >= lone && l <= LogicalKeyboardKey.digit9.keyId) return 1 + l - lone;
+ final lpad = LogicalKeyboardKey.numpad1.keyId;
+ if (l >= lpad && l <= LogicalKeyboardKey.numpad9.keyId) return 1 + l - lpad;
return null;
}
diff --git a/ui/test/picker_test.dart b/ui/test/picker_test.dart
index 07f4502..7629ca4 100644
--- a/ui/test/picker_test.dart
+++ b/ui/test/picker_test.dart
@@ -127,6 +127,14 @@ void main() {
expect(commits().single.arguments, {'paste': true});
});
+ testWidgets('模拟输入没有扫描码、认不出物理按键时,按逻辑按键认数字', (tester) async {
+ final s = await open(tester);
+ await tester.sendKeyDownEvent(LogicalKeyboardKey.digit3, physicalKey: PhysicalKeyboardKey.keyQ);
+ await tester.sendKeyUpEvent(LogicalKeyboardKey.digit3, physicalKey: PhysicalKeyboardKey.keyQ);
+ await tester.pump();
+ expect(s.applied, [('c', false)]);
+ });
+
testWidgets('输入法收下数字键、只交来文字时(Windows 中文输入法),也按数字选那一行', (tester) async {
final s = await open(tester);
final field = tester.widget<TextField>(find.byType(TextField));