Adds macOS raw keyboard mapping (#29231)
This commit is contained in:
committed by
GitHub
parent
75c50da5f6
commit
c163ed9618
@@ -92,6 +92,11 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
|
||||
dataText.add(Text('codePoint: ${data.codePoint} (${_asHex(data.codePoint)})'));
|
||||
dataText.add(Text('hidUsage: ${data.hidUsage} (${_asHex(data.hidUsage)})'));
|
||||
dataText.add(Text('modifiers: ${data.modifiers} (${_asHex(data.modifiers)})'));
|
||||
} else if (data is RawKeyEventDataMacOs) {
|
||||
dataText.add(Text('keyCode: ${data.keyCode} (${_asHex(data.keyCode)})'));
|
||||
dataText.add(Text('characters: ${data.characters}'));
|
||||
dataText.add(Text('charactersIgnoringModifiers: ${data.charactersIgnoringModifiers}'));
|
||||
dataText.add(Text('modifiers: ${data.modifiers} (${_asHex(data.modifiers)})'));
|
||||
}
|
||||
dataText.add(Text('logical: ${_event.logicalKey}'));
|
||||
dataText.add(Text('physical: ${_event.physicalKey}'));
|
||||
|
||||
@@ -38,3 +38,15 @@ const Map<int, LogicalKeyboardKey> kFuchsiaToLogicalKey = <int, LogicalKeyboardK
|
||||
const Map<int, PhysicalKeyboardKey> kFuchsiaToPhysicalKey = <int, PhysicalKeyboardKey>{
|
||||
@@@FUCHSIA_SCAN_CODE_MAP@@@
|
||||
};
|
||||
|
||||
/// Maps macOS-specific key code values representing [PhysicalKeyboardKey].
|
||||
const Map<int, PhysicalKeyboardKey> kMacOsToPhysicalKey = <int, PhysicalKeyboardKey>{
|
||||
@@@MACOS_SCAN_CODE_MAP@@@
|
||||
};
|
||||
|
||||
/// A map of macOS key codes which have printable representations, but appear
|
||||
/// on the number pad. Used to provide different key objects for keys like
|
||||
/// KEY_EQUALS and NUMPAD_EQUALS.
|
||||
const Map<int, LogicalKeyboardKey> kMacOsNumPadMap = <int, LogicalKeyboardKey>{
|
||||
@@@MACOS_NUMPAD_MAP@@@
|
||||
};
|
||||
|
||||
@@ -135,6 +135,31 @@ $otherComments static const LogicalKeyboardKey ${entry.constantName} = LogicalK
|
||||
return androidScanCodeMap.toString().trimRight();
|
||||
}
|
||||
|
||||
/// This generates the map of macOS key codes to physical keys.
|
||||
String get macOsScanCodeMap {
|
||||
final StringBuffer macOsScanCodeMap = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
if (entry.macOsScanCode != null) {
|
||||
macOsScanCodeMap.writeln(' ${toHex(entry.macOsScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
}
|
||||
return macOsScanCodeMap.toString().trimRight();
|
||||
}
|
||||
|
||||
/// This generates the map of macOS number pad key codes to logical keys.
|
||||
String get macOsNumpadMap {
|
||||
final StringBuffer macOsNumPadMap = StringBuffer();
|
||||
final List<Key> onlyNumpads = keyData.data.where((Key entry) {
|
||||
return entry.constantName.startsWith('numpad') && entry.keyLabel != null;
|
||||
}).toList();
|
||||
for (Key entry in onlyNumpads) {
|
||||
if (entry.macOsScanCode != null) {
|
||||
macOsNumPadMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
}
|
||||
return macOsNumPadMap.toString().trimRight();
|
||||
}
|
||||
|
||||
/// This generates the map of Fuchsia key codes to logical keys.
|
||||
String get fuchsiaKeyCodeMap {
|
||||
final StringBuffer fuchsiaKeyCodeMap = StringBuffer();
|
||||
@@ -174,12 +199,17 @@ $otherComments static const LogicalKeyboardKey ${entry.constantName} = LogicalK
|
||||
/// Substitutes the various platform specific maps into the template file for
|
||||
/// keyboard_maps.dart.
|
||||
String generateKeyboardMaps() {
|
||||
// There is no macOS keycode map since macOS uses keycode to represent a physical key.
|
||||
// The LogicalKeyboardKey is generated by raw_keyboard_macos.dart from the unmodified characters
|
||||
// from NSEvent.
|
||||
final Map<String, String> mappings = <String, String>{
|
||||
'ANDROID_SCAN_CODE_MAP': androidScanCodeMap,
|
||||
'ANDROID_KEY_CODE_MAP': androidKeyCodeMap,
|
||||
'ANDROID_NUMPAD_MAP': androidNumpadMap,
|
||||
'FUCHSIA_SCAN_CODE_MAP': fuchsiaHidCodeMap,
|
||||
'FUCHSIA_KEY_CODE_MAP': fuchsiaKeyCodeMap,
|
||||
'MACOS_SCAN_CODE_MAP': macOsScanCodeMap,
|
||||
'MACOS_NUMPAD_MAP': macOsNumpadMap,
|
||||
};
|
||||
|
||||
final String template = File(path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_maps.tmpl')).readAsStringSync();
|
||||
|
||||
Reference in New Issue
Block a user