diff --git a/dev/tools/gen_keycodes/data/ios_logical_to_physical.json b/dev/tools/gen_keycodes/data/ios_logical_to_physical.json index d1fb1171f2..49a0acaea3 100644 --- a/dev/tools/gen_keycodes/data/ios_logical_to_physical.json +++ b/dev/tools/gen_keycodes/data/ios_logical_to_physical.json @@ -1,6 +1,8 @@ { "Backspace": ["Backspace"], + "Tab": ["Tab"], + "Enter": ["Enter"], "Escape": ["Escape"], "CapsLock": ["CapsLock"], "NumLock": ["NumLock"], diff --git a/dev/tools/gen_keycodes/data/logical_key_data.json b/dev/tools/gen_keycodes/data/logical_key_data.json index e2584f193e..16b10799eb 100644 --- a/dev/tools/gen_keycodes/data/logical_key_data.json +++ b/dev/tools/gen_keycodes/data/logical_key_data.json @@ -1383,6 +1383,12 @@ "web": [ "Tab" ], + "macOs": [ + "Tab" + ], + "ios": [ + "Tab" + ], "gtk": [ "Tab", "KP_Tab", @@ -1396,6 +1402,12 @@ ] }, "values": { + "macOs": [ + 48 + ], + "ios": [ + 43 + ], "gtk": [ 65289, 65417, @@ -1420,6 +1432,12 @@ "web": [ "Enter" ], + "macOs": [ + "Enter" + ], + "ios": [ + "Enter" + ], "gtk": [ "Return", "ISO_Enter", @@ -1433,6 +1451,12 @@ ] }, "values": { + "macOs": [ + 36 + ], + "ios": [ + 40 + ], "gtk": [ 65293, 65076, diff --git a/dev/tools/gen_keycodes/data/macos_logical_to_physical.json b/dev/tools/gen_keycodes/data/macos_logical_to_physical.json index 996cf5e868..e82db40260 100644 --- a/dev/tools/gen_keycodes/data/macos_logical_to_physical.json +++ b/dev/tools/gen_keycodes/data/macos_logical_to_physical.json @@ -1,6 +1,8 @@ { "Backspace": ["Backspace"], + "Tab": ["Tab"], + "Enter": ["Enter"], "Escape": ["Escape"], "CapsLock": ["CapsLock"], "Fn": ["Fn"], diff --git a/dev/tools/gen_keycodes/lib/logical_key_data.dart b/dev/tools/gen_keycodes/lib/logical_key_data.dart index 04c7112bef..f2d2ecfe83 100644 --- a/dev/tools/gen_keycodes/lib/logical_key_data.dart +++ b/dev/tools/gen_keycodes/lib/logical_key_data.dart @@ -193,7 +193,7 @@ class LogicalKeyData { // Make sure every Numpad key that we care about has been defined. unusedNumpad.forEach((String key, String value) { - print('Unuadded numpad key $value'); + print('Undefined numpad key $value'); }); } diff --git a/packages/flutter/lib/src/services/keyboard_maps.dart b/packages/flutter/lib/src/services/keyboard_maps.dart index c7c5f9b387..c2471dbe5b 100644 --- a/packages/flutter/lib/src/services/keyboard_maps.dart +++ b/packages/flutter/lib/src/services/keyboard_maps.dart @@ -1226,6 +1226,8 @@ const Map kMacOsFunctionKeyMap = kMacOsToLogicalKey = { + 36: LogicalKeyboardKey.enter, + 48: LogicalKeyboardKey.tab, 51: LogicalKeyboardKey.backspace, 53: LogicalKeyboardKey.escape, 54: LogicalKeyboardKey.metaRight, @@ -1494,8 +1496,10 @@ const Map kIosNumPadMap = { /// have a character representation will be derived from their key codes using /// this map. const Map kIosToLogicalKey = { + 40: LogicalKeyboardKey.enter, 41: LogicalKeyboardKey.escape, 42: LogicalKeyboardKey.backspace, + 43: LogicalKeyboardKey.tab, 57: LogicalKeyboardKey.capsLock, 58: LogicalKeyboardKey.f1, 59: LogicalKeyboardKey.f2, diff --git a/packages/flutter/lib/src/services/raw_keyboard_ios.dart b/packages/flutter/lib/src/services/raw_keyboard_ios.dart index bbf64012d7..7a7eacf6b0 100644 --- a/packages/flutter/lib/src/services/raw_keyboard_ios.dart +++ b/packages/flutter/lib/src/services/raw_keyboard_ios.dart @@ -120,7 +120,8 @@ class RawKeyEventDataIos extends RawKeyEventData { // printable. HOME, DEL, arrow keys, and function keys are considered // modifier function keys, which generate invalid Unicode scalar values. if (keyLabel.isNotEmpty && - !LogicalKeyboardKey.isControlCharacter(keyLabel)) { + !LogicalKeyboardKey.isControlCharacter(keyLabel) && + !_isUnprintableKey(keyLabel)) { // Given that charactersIgnoringModifiers can contain a String of // arbitrary length, limit to a maximum of two Unicode scalar values. It // is unlikely that a keyboard would produce a code point bigger than 32 @@ -154,6 +155,23 @@ class RawKeyEventDataIos extends RawKeyEventData { return LogicalKeyboardKey(iosKeyIdPlane | keyCode | LogicalKeyboardKey.autogeneratedMask); } + /// Returns true if the given label represents an unprintable key. + /// + /// Examples of unprintable keys are "NSUpArrowFunctionKey = 0xF700" + /// or "NSHomeFunctionKey = 0xF729". + /// + /// See for more + /// information. + /// + /// Used by [RawKeyEvent] subclasses to help construct IDs. + static bool _isUnprintableKey(String label) { + if (label.length != 1) { + return false; + } + final int codeUnit = label.codeUnitAt(0); + return codeUnit >= 0xF700 && codeUnit <= 0xF8FF; + } + bool _isLeftRightModifierPressed(KeyboardSide side, int anyMask, int leftMask, int rightMask) { if (modifiers & anyMask == 0) { return false; diff --git a/packages/flutter/test/services/keyboard_key_test.dart b/packages/flutter/test/services/keyboard_key_test.dart index 0c49dc9ab9..c41b214dc5 100644 --- a/packages/flutter/test/services/keyboard_key_test.dart +++ b/packages/flutter/test/services/keyboard_key_test.dart @@ -38,6 +38,7 @@ void main() { test('Control characters are recognized as such', () async { // Check some common control characters expect(LogicalKeyboardKey.isControlCharacter('\x08'), isTrue); // BACKSPACE + expect(LogicalKeyboardKey.isControlCharacter('\x09'), isTrue); // TAB expect(LogicalKeyboardKey.isControlCharacter('\x0a'), isTrue); // LINE FEED expect(LogicalKeyboardKey.isControlCharacter('\x0d'), isTrue); // RETURN expect(LogicalKeyboardKey.isControlCharacter('\x1b'), isTrue); // ESC @@ -48,6 +49,16 @@ void main() { expect(LogicalKeyboardKey.isControlCharacter('~'), isFalse); expect(LogicalKeyboardKey.isControlCharacter('\xa0'), isFalse); // NO-BREAK SPACE }); + test('Control characters are not using incorrect values', () async { + const int kUnprintablePlane = 0x01000000000; + // Check some common control characters to make sure they're using + // their char code values, and not something else. + expect(LogicalKeyboardKey.backspace.keyId, equals(kUnprintablePlane + 0x08)); + expect(LogicalKeyboardKey.tab.keyId, equals(kUnprintablePlane + 0x09)); + expect(LogicalKeyboardKey.enter.keyId, equals(kUnprintablePlane + 0x0d)); + expect(LogicalKeyboardKey.escape.keyId, equals(kUnprintablePlane + 0x1b)); + expect(LogicalKeyboardKey.delete.keyId, equals(kUnprintablePlane + 0x7f)); + }); test('Basic synonyms can be looked up.', () async { expect(LogicalKeyboardKey.shiftLeft.synonyms.first, equals(LogicalKeyboardKey.shift)); expect(LogicalKeyboardKey.controlLeft.synonyms.first, equals(LogicalKeyboardKey.control));