diff --git a/dev/tools/gen_keycodes/data/web_logical_location_mapping.json b/dev/tools/gen_keycodes/data/web_logical_location_mapping.json index c5b19daf191..dd06fd11798 100644 --- a/dev/tools/gen_keycodes/data/web_logical_location_mapping.json +++ b/dev/tools/gen_keycodes/data/web_logical_location_mapping.json @@ -26,8 +26,8 @@ "-": ["Minus", null, null, "NumpadSubtract"], "+": ["Add", null, null, "NumpadAdd"], "Enter": ["Enter", null, null, "NumpadEnter"], - "Shift": [null, "ShiftLeft", "ShiftRight", null], - "Control": [null, "ControlLeft", "ControlRight", null], - "Alt": [null, "AltLeft", "AltRight", null], - "Meta": [null, "MetaLeft", "MetaRight", null] + "Shift": ["ShiftLeft", "ShiftLeft", "ShiftRight", null], + "Control": ["ControlLeft", "ControlLeft", "ControlRight", null], + "Alt": ["AltLeft", "AltLeft", "AltRight", null], + "Meta": ["MetaLeft", "MetaLeft", "MetaRight", null] } diff --git a/packages/flutter/lib/src/services/keyboard_maps.dart b/packages/flutter/lib/src/services/keyboard_maps.dart index 3375b30b77e..89453719af7 100644 --- a/packages/flutter/lib/src/services/keyboard_maps.dart +++ b/packages/flutter/lib/src/services/keyboard_maps.dart @@ -2760,22 +2760,22 @@ const Map> kWebLocationMap = [LogicalKeyboardKey.digit7, null, null, LogicalKeyboardKey.numpad7], '8': [LogicalKeyboardKey.digit8, null, null, LogicalKeyboardKey.numpad8], '9': [LogicalKeyboardKey.digit9, null, null, LogicalKeyboardKey.numpad9], - 'Alt': [null, LogicalKeyboardKey.altLeft, LogicalKeyboardKey.altRight, null], + 'Alt': [LogicalKeyboardKey.altLeft, LogicalKeyboardKey.altLeft, LogicalKeyboardKey.altRight, null], 'ArrowDown': [LogicalKeyboardKey.arrowDown, null, null, LogicalKeyboardKey.numpad2], 'ArrowLeft': [LogicalKeyboardKey.arrowLeft, null, null, LogicalKeyboardKey.numpad4], 'ArrowRight': [LogicalKeyboardKey.arrowRight, null, null, LogicalKeyboardKey.numpad6], 'ArrowUp': [LogicalKeyboardKey.arrowUp, null, null, LogicalKeyboardKey.numpad8], 'Clear': [LogicalKeyboardKey.clear, null, null, LogicalKeyboardKey.numpad5], - 'Control': [null, LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.controlRight, null], + 'Control': [LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.controlRight, null], 'Delete': [LogicalKeyboardKey.delete, null, null, LogicalKeyboardKey.numpadDecimal], 'End': [LogicalKeyboardKey.end, null, null, LogicalKeyboardKey.numpad1], 'Enter': [LogicalKeyboardKey.enter, null, null, LogicalKeyboardKey.numpadEnter], 'Home': [LogicalKeyboardKey.home, null, null, LogicalKeyboardKey.numpad7], 'Insert': [LogicalKeyboardKey.insert, null, null, LogicalKeyboardKey.numpad0], - 'Meta': [null, LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.metaRight, null], + 'Meta': [LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.metaRight, null], 'PageDown': [LogicalKeyboardKey.pageDown, null, null, LogicalKeyboardKey.numpad3], 'PageUp': [LogicalKeyboardKey.pageUp, null, null, LogicalKeyboardKey.numpad9], - 'Shift': [null, LogicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftRight, null], + 'Shift': [LogicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftRight, null], }; /// Maps Windows KeyboardEvent codes to the matching [LogicalKeyboardKey]. diff --git a/packages/flutter/test/services/raw_keyboard_test.dart b/packages/flutter/test/services/raw_keyboard_test.dart index 45d801c8f90..033e07686e4 100644 --- a/packages/flutter/test/services/raw_keyboard_test.dart +++ b/packages/flutter/test/services/raw_keyboard_test.dart @@ -2479,6 +2479,14 @@ void main() { RawKeyEventDataWeb.modifierScrollLock: ModifierKey.scrollLockModifier, }; + const Map modifierTestsWithNoLocation = + { + 'Alt': LogicalKeyboardKey.altLeft, + 'Shift': LogicalKeyboardKey.shiftLeft, + 'Control': LogicalKeyboardKey.controlLeft, + 'Meta': LogicalKeyboardKey.metaLeft, + }; + test('modifier keys are recognized individually', () { for (final int modifier in modifierTests.keys) { final RawKeyEvent event = RawKeyEvent.fromMessage({ @@ -2539,6 +2547,19 @@ void main() { } }); + test('modifier keys with no location are mapped to left', () { + for (final String modifierKey in modifierTestsWithNoLocation.keys) { + final RawKeyEvent event = RawKeyEvent.fromMessage({ + 'type': 'keydown', + 'keymap': 'web', + 'key': modifierKey, + 'location': 0, + }); + final RawKeyEventDataWeb data = event.data as RawKeyEventDataWeb; + expect(data.logicalKey, modifierTestsWithNoLocation[modifierKey]); + } + }); + test('Lower letter keys are correctly translated', () { final RawKeyEvent keyAEvent = RawKeyEvent.fromMessage(const { 'type': 'keydown', diff --git a/packages/flutter_test/lib/src/event_simulation.dart b/packages/flutter_test/lib/src/event_simulation.dart index aee135812cd..92ccb7e7f91 100644 --- a/packages/flutter_test/lib/src/event_simulation.dart +++ b/packages/flutter_test/lib/src/event_simulation.dart @@ -169,7 +169,7 @@ class KeyEventSimulator { static _WebKeyLocationPair _getWebKeyLocation(LogicalKeyboardKey key, String keyLabel) { String? result; for (final MapEntry> entry in kWebLocationMap.entries) { - final int foundIndex = entry.value.indexOf(key); + final int foundIndex = entry.value.lastIndexOf(key); // If foundIndex is -1, then the key is not defined in kWebLocationMap. // If foundIndex is 0, then the key is in the standard part of the keyboard, // but we have to check `keyLabel` to see if it's remapped or modified.