Keymap for Web (#41397)
This commit is contained in:
@@ -70,3 +70,20 @@ const Map<int, PhysicalKeyboardKey> kLinuxToPhysicalKey = <int, PhysicalKeyboard
|
||||
@@@XKB_SCAN_CODE_MAP@@@
|
||||
};
|
||||
|
||||
/// Maps Web KeyboardEvent codes to the matching [LogicalKeyboardKey].
|
||||
const Map<String, LogicalKeyboardKey> kWebToLogicalKey = <String, LogicalKeyboardKey>{
|
||||
@@@WEB_LOGICAL_KEY_MAP@@@
|
||||
};
|
||||
|
||||
/// Maps Web KeyboardEvent codes to the matching [PhysicalKeyboardKey].
|
||||
const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyboardKey>{
|
||||
@@@WEB_PHYSICAL_KEY_MAP@@@
|
||||
};
|
||||
|
||||
/// A map of Web KeyboardEvent 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<String, LogicalKeyboardKey> kWebNumPadMap = <String, LogicalKeyboardKey>{
|
||||
@@@WEB_NUMPAD_MAP@@@
|
||||
};
|
||||
|
||||
|
||||
@@ -108,6 +108,12 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
return synonyms.toString();
|
||||
}
|
||||
|
||||
List<Key> get numpadKeyData {
|
||||
return keyData.data.where((Key entry) {
|
||||
return entry.constantName.startsWith('numpad') && entry.keyLabel != null;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
/// This generates the map of USB HID codes to physical keys.
|
||||
String get predefinedHidCodeMap {
|
||||
final StringBuffer scanCodeMap = StringBuffer();
|
||||
@@ -139,10 +145,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of GLFW number pad key codes to logical keys.
|
||||
String get glfwNumpadMap {
|
||||
final StringBuffer glfwNumpadMap = StringBuffer();
|
||||
final List<Key> onlyNumpads = keyData.data.where((Key entry) {
|
||||
return entry.constantName.startsWith('numpad') && entry.keyLabel != null;
|
||||
}).toList();
|
||||
for (Key entry in onlyNumpads) {
|
||||
for (Key entry in numpadKeyData) {
|
||||
if (entry.glfwKeyCodes != null) {
|
||||
for (int code in entry.glfwKeyCodes.cast<int>()) {
|
||||
glfwNumpadMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
|
||||
@@ -192,10 +195,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of Android number pad key codes to logical keys.
|
||||
String get androidNumpadMap {
|
||||
final StringBuffer androidKeyCodeMap = StringBuffer();
|
||||
final List<Key> onlyNumpads = keyData.data.where((Key entry) {
|
||||
return entry.constantName.startsWith('numpad') && entry.keyLabel != null;
|
||||
}).toList();
|
||||
for (Key entry in onlyNumpads) {
|
||||
for (Key entry in numpadKeyData) {
|
||||
if (entry.androidKeyCodes != null) {
|
||||
for (int code in entry.androidKeyCodes.cast<int>()) {
|
||||
androidKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
|
||||
@@ -232,10 +232,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// 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) {
|
||||
for (Key entry in numpadKeyData) {
|
||||
if (entry.macOsScanCode != null) {
|
||||
macOsNumPadMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
@@ -265,6 +262,39 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
return fuchsiaScanCodeMap.toString().trimRight();
|
||||
}
|
||||
|
||||
/// This generates the map of Web KeyboardEvent codes to logical keys.
|
||||
String get webLogicalKeyMap {
|
||||
final StringBuffer result = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
if (entry.name != null) {
|
||||
result.writeln(" '${entry.name}': LogicalKeyboardKey.${entry.constantName},");
|
||||
}
|
||||
}
|
||||
return result.toString().trimRight();
|
||||
}
|
||||
|
||||
/// This generates the map of Web KeyboardEvent codes to physical keys.
|
||||
String get webPhysicalKeyMap {
|
||||
final StringBuffer result = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
if (entry.name != null) {
|
||||
result.writeln(" '${entry.name}': PhysicalKeyboardKey.${entry.constantName},");
|
||||
}
|
||||
}
|
||||
return result.toString().trimRight();
|
||||
}
|
||||
|
||||
/// This generates the map of Web number pad codes to logical keys.
|
||||
String get webNumpadMap {
|
||||
final StringBuffer result = StringBuffer();
|
||||
for (Key entry in numpadKeyData) {
|
||||
if (entry.name != null) {
|
||||
result.writeln(" '${entry.name}': LogicalKeyboardKey.${entry.constantName},");
|
||||
}
|
||||
}
|
||||
return result.toString().trimRight();
|
||||
}
|
||||
|
||||
/// Substitutes the various maps and definitions into the template file for
|
||||
/// keyboard_key.dart.
|
||||
String generateKeyboardKeys() {
|
||||
@@ -297,6 +327,9 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
'GLFW_KEY_CODE_MAP': glfwKeyCodeMap,
|
||||
'GLFW_NUMPAD_MAP': glfwNumpadMap,
|
||||
'XKB_SCAN_CODE_MAP': xkbScanCodeMap,
|
||||
'WEB_LOGICAL_KEY_MAP': webLogicalKeyMap,
|
||||
'WEB_PHYSICAL_KEY_MAP': webPhysicalKeyMap,
|
||||
'WEB_NUMPAD_MAP': webNumpadMap,
|
||||
};
|
||||
|
||||
final String template = File(path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_maps.tmpl')).readAsStringSync();
|
||||
|
||||
Reference in New Issue
Block a user