[Keyboard] Collects windows key data (#52265)

This commit is contained in:
Francisco Magdaleno
2020-03-09 17:21:02 -07:00
committed by GitHub
parent bc43b41d99
commit e9905b6ad8
8 changed files with 1783 additions and 394 deletions

View File

@@ -17,7 +17,7 @@ import 'package:gen_keycodes/utils.dart';
/// Get contents of the file that contains the key code mapping in Chromium
/// source.
Future<String> getChromiumConversions() async {
final Uri keyCodeMapUri = Uri.parse('https://cs.chromium.org/codesearch/f/chromium/src/ui/events/keycodes/dom/keycode_converter_data.inc');
final Uri keyCodeMapUri = Uri.parse('https://cs.chromium.org/codesearch/f/chromium/src/ui/events/keycodes/dom/dom_code_data.inc');
return await http.read(keyCodeMapUri);
}
@@ -27,6 +27,11 @@ Future<String> getAndroidKeyCodes() async {
return utf8.decode(base64.decode(await http.read(keyCodesUri)));
}
Future<String> getWindowsKeyCodes() async {
final Uri keyCodesUri = Uri.parse('https://raw.githubusercontent.com/tpn/winsdk-10/master/Include/10.0.10240.0/um/WinUser.h');
return await http.read(keyCodesUri);
}
/// Get contents of the file that contains the scan codes in Android source.
/// Yes, this is just the generic keyboard layout file for base Android distro
/// This is because there isn't any facility in Android to get the keyboard
@@ -84,12 +89,23 @@ Future<void> main(List<String> rawArguments) async {
'If --glfw-keycodes is not specified, the input will be read from the '
'correct file in the GLFW github repository.',
);
argParser.addOption(
argParser.addOption(
'windows-keycodes',
defaultsTo: null,
help: 'The path to where the Windows keycodes header file should be read. '
'If --windows-keycodes is not specified, the input will be read from the '
'correct file in the Windows github repository.',
);
argParser.addOption(
'windows-domkey',
defaultsTo: path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'key_name_to_windows_name.json'),
help: 'The path to where the Windows keycode to DomKey mapping is.',
);
argParser.addOption(
'glfw-domkey',
defaultsTo: path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'key_name_to_glfw_name.json'),
help: 'The path to where the GLFW keycode to DomKey mapping is.',
);
argParser.addOption(
'data',
defaultsTo: path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'key_data.json'),
@@ -170,10 +186,18 @@ Future<void> main(List<String> rawArguments) async {
glfwKeyCodes = File(parsedArguments['glfw-keycodes'] as String).readAsStringSync();
}
String windowsKeyCodes;
if (parsedArguments['windows-keycodes'] == null) {
windowsKeyCodes = await getWindowsKeyCodes();
} else {
windowsKeyCodes = File(parsedArguments['windows-keycodes'] as String).readAsStringSync();
}
final String windowsToDomKey = File(parsedArguments['windows-domkey'] as String).readAsStringSync();
final String glfwToDomKey = File(parsedArguments['glfw-domkey'] as String).readAsStringSync();
final String androidToDomKey = File(parsedArguments['android-domkey'] as String).readAsStringSync();
data = KeyData(hidCodes, androidScanCodes, androidKeyCodes, androidToDomKey, glfwKeyCodes, glfwToDomKey);
data = KeyData(hidCodes, androidScanCodes, androidKeyCodes, androidToDomKey, glfwKeyCodes, glfwToDomKey, windowsKeyCodes, windowsToDomKey);
const JsonEncoder encoder = JsonEncoder.withIndent(' ');
File(parsedArguments['data'] as String).writeAsStringSync(encoder.convert(data.toJson()));

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,230 @@
{
"leftMouseButton": ["LBUTTON"],
"rightMouseButton": ["RBUTTON"],
"cancel": ["CANCEL"],
"middleMouseButton": ["MBUTTON"],
"xMouseButton1": ["XBUTTON1"],
"xMouseButton2": ["XBUTTON2"],
"backspace": ["BACK"],
"tab": ["TAB"],
"clear": ["CLEAR"],
"enter": ["RETURN"],
"shift": ["SHIFT"],
"control": ["CONTROL"],
"menu": ["MENU"],
"pause": ["PAUSE"],
"capsLock": ["CAPITAL"],
"kana": ["KANA"],
"hangeul": ["HANGEUL"],
"hangul": ["HANGUL"],
"junja": ["JUNJA"],
"final": ["FINAL"],
"hanja": ["HANJA"],
"kanji": ["KANJI"],
"escape": ["ESCAPE"],
"convert": ["CONVERT"],
"nonconvert": ["NONCONVERT"],
"accept": ["ACCEPT"],
"modeChange": ["MODECHANGE"],
"space": ["SPACE"],
"prior": ["PRIOR"],
"next": ["NEXT"],
"end": ["END"],
"home": ["HOME"],
"leftArrow": ["LEFT"],
"upArrow": ["UP"],
"rightArrow": ["RIGHT"],
"downArrow": ["DOWN"],
"select": ["SELECT"],
"print": ["PRINT"],
"execute": ["EXECUTE"],
"snapshot": ["SNAPSHOT"],
"insert": ["INSERT"],
"delete": ["DELETE"],
"help": ["HELP"],
"metaLeft": ["LWIN"],
"metaRight": ["RWIN"],
"apps": ["APPS"],
"sleep": ["SLEEP"],
"numpad0": ["NUMPAD0"],
"numpad1": ["NUMPAD1"],
"numpad2": ["NUMPAD2"],
"numpad3": ["NUMPAD3"],
"numpad4": ["NUMPAD4"],
"numpad5": ["NUMPAD5"],
"numpad6": ["NUMPAD6"],
"numpad7": ["NUMPAD7"],
"numpad8": ["NUMPAD8"],
"numpad9": ["NUMPAD9"],
"numpadMultiply": ["MULTIPLY"],
"numpadAdd": ["ADD"],
"numpadSeparator": ["SEPARATOR"],
"numpadSubtract": ["SUBTRACT"],
"numpadDecimal": ["DECIMAL"],
"numpadDivide": ["DIVIDE"],
"f1": ["F1"],
"f2": ["F2"],
"f3": ["F3"],
"f4": ["F4"],
"f5": ["F5"],
"f6": ["F6"],
"f7": ["F7"],
"f8": ["F8"],
"f9": ["F9"],
"f10": ["F10"],
"f11": ["F11"],
"f12": ["F12"],
"f13": ["F13"],
"f14": ["F14"],
"f15": ["F15"],
"f16": ["F16"],
"f17": ["F17"],
"f18": ["F18"],
"f19": ["F19"],
"f20": ["F20"],
"f21": ["F21"],
"f22": ["F22"],
"f23": ["F23"],
"f24": ["F24"],
"navigationView": ["NAVIGATION_VIEW"],
"navigationMenu": ["NAVIGATION_MENU"],
"navigationUp": ["NAVIGATION_UP"],
"navigationDown": ["NAVIGATION_DOWN"],
"navigationLeft": ["NAVIGATION_LEFT"],
"navigationRight": ["NAVIGATION_RIGHT"],
"navigationAccept": ["NAVIGATION_ACCEPT"],
"navigationCancel": ["NAVIGATION_CANCEL"],
"numlock": ["NUMLOCK"],
"scroll": ["SCROLL"],
"numpadEqual": ["OEM_NEC_EQUAL"],
"oemFjJisho": ["OEM_FJ_JISHO"],
"oemFjMasshou": ["OEM_FJ_MASSHOU"],
"oemFjTouroku": ["OEM_FJ_TOUROKU"],
"oemFjLoya": ["OEM_FJ_LOYA"],
"oemFjRoya": ["OEM_FJ_ROYA"],
"shiftLeft": ["LSHIFT"],
"shiftRight": ["RSHIFT"],
"controlLeft": ["LCONTROL"],
"controlRight": ["RCONTROL"],
"altLeft": ["LMENU"],
"altRight": ["RMENU"],
"browserBack": ["BROWSER_BACK"],
"browserForward": ["BROWSER_FORWARD"],
"browserRefresh": ["BROWSER_REFRESH"],
"browserStop": ["BROWSER_STOP"],
"browserSearch": ["BROWSER_SEARCH"],
"browserFavorites": ["BROWSER_FAVORITES"],
"browserHome": ["BROWSER_HOME"],
"volumeMute": ["VOLUME_MUTE"],
"volumeDown": ["VOLUME_DOWN"],
"volumeUp": ["VOLUME_UP"],
"mediaNextTrack": ["MEDIA_NEXT_TRACK"],
"mediaPrevTrack": ["MEDIA_PREV_TRACK"],
"mediaStop": ["MEDIA_STOP"],
"mediaPlayPause": ["MEDIA_PLAY_PAUSE"],
"launchMail": ["LAUNCH_MAIL"],
"launchMediaSelect": ["LAUNCH_MEDIA_SELECT"],
"launchApp1": ["LAUNCH_APP1"],
"launchApp2": ["LAUNCH_APP2"],
"semicolon": ["OEM_1"],
"equal": ["OEM_PLUS"],
"comma": ["OEM_COMMA"],
"minus": ["OEM_MINUS"],
"period": ["OEM_PERIOD"],
"slash": ["OEM_2"],
"backQuote": ["OEM_3"],
"gamepadA": ["GAMEPAD_A"],
"gamepadB": ["GAMEPAD_B"],
"gamepadX": ["GAMEPAD_X"],
"gamepadY": ["GAMEPAD_Y"],
"gamepadRightShoulder": ["GAMEPAD_RIGHT_SHOULDER"],
"gamepadLeftShoulder": ["GAMEPAD_LEFT_SHOULDER"],
"gamepadLeftTrigger": ["GAMEPAD_LEFT_TRIGGER"],
"gamepadRightTrigger": ["GAMEPAD_RIGHT_TRIGGER"],
"gamepadDpadUp": ["GAMEPAD_DPAD_UP"],
"gamepadDpadDown": ["GAMEPAD_DPAD_DOWN"],
"gamepadDpadLeft": ["GAMEPAD_DPAD_LEFT"],
"gamepadDpadRight": ["GAMEPAD_DPAD_RIGHT"],
"gamepadMenu": ["GAMEPAD_MENU"],
"gamepadView": ["GAMEPAD_VIEW"],
"gamepadLeftThumbstickButton": ["GAMEPAD_LEFT_THUMBSTICK_BUTTON"],
"gamepadRightThumbstickButton": ["GAMEPAD_RIGHT_THUMBSTICK_BUTTON"],
"gamepadLeftThumbstickUp": ["GAMEPAD_LEFT_THUMBSTICK_UP"],
"gamepadLeftThumbstickDown": ["GAMEPAD_LEFT_THUMBSTICK_DOWN"],
"gamepadLeftThumbstickRight": ["GAMEPAD_LEFT_THUMBSTICK_RIGHT"],
"gamepadLeftThumbstickLeft": ["GAMEPAD_LEFT_THUMBSTICK_LEFT"],
"gamepadRightThumbstickUp": ["GAMEPAD_RIGHT_THUMBSTICK_UP"],
"gamepadRightThumbstickDown": ["GAMEPAD_RIGHT_THUMBSTICK_DOWN"],
"gamepadRightThumbstickRight": ["GAMEPAD_RIGHT_THUMBSTICK_RIGHT"],
"gamepadRightThumbstickLeft": ["GAMEPAD_RIGHT_THUMBSTICK_LEFT"],
"bracketLeft": ["OEM_4"],
"backslash": ["OEM_5"],
"bracketRight": ["OEM_6"],
"quote": ["OEM_7"],
"oem8": ["OEM_8"],
"oemAx": ["OEM_AX"],
"oem102": ["OEM_102"],
"icoHelp": ["ICO_HELP"],
"ico00": ["ICO_00"],
"processkey": ["PROCESSKEY"],
"icoClear": ["ICO_CLEAR"],
"packet": ["PACKET"],
"oemReset": ["OEM_RESET"],
"oemJump": ["OEM_JUMP"],
"oemPa1": ["OEM_PA1"],
"oemPa2": ["OEM_PA2"],
"oemPa3": ["OEM_PA3"],
"oemWsctrl": ["OEM_WSCTRL"],
"oemCusel": ["OEM_CUSEL"],
"oemAttn": ["OEM_ATTN"],
"oemFinish": ["OEM_FINISH"],
"oemCopy": ["OEM_COPY"],
"oemAuto": ["OEM_AUTO"],
"oemEnlw": ["OEM_ENLW"],
"oemBacktab": ["OEM_BACKTAB"],
"attn": ["ATTN"],
"crsel": ["CRSEL"],
"exsel": ["EXSEL"],
"ereof": ["EREOF"],
"play": ["PLAY"],
"zoom": ["ZOOM"],
"noname": ["NONAME"],
"pa1": ["PA1"],
"oemClear": ["OEM_CLEAR"],
"0": ["0"],
"1": ["1"],
"2": ["2"],
"3": ["3"],
"4": ["4"],
"5": ["5"],
"6": ["6"],
"7": ["7"],
"8": ["8"],
"9": ["9"],
"keyA": ["A"],
"keyB": ["B"],
"keyC": ["C"],
"keyD": ["D"],
"keyE": ["E"],
"keyF": ["F"],
"keyG": ["G"],
"keyH": ["H"],
"keyI": ["I"],
"keyJ": ["J"],
"keyK": ["K"],
"keyL": ["L"],
"keyM": ["M"],
"keyN": ["N"],
"keyO": ["O"],
"keyP": ["P"],
"keyQ": ["Q"],
"keyR": ["R"],
"keyS": ["S"],
"keyT": ["T"],
"keyU": ["U"],
"keyV": ["V"],
"keyW": ["W"],
"keyX": ["X"],
"keyY": ["Y"],
"keyZ": ["Z"]
}

View File

@@ -45,7 +45,7 @@ abstract class KeyboardKey extends Diagnosticable {
/// look at the physical key to make sure that regardless of the character the
/// key produces, you got the key that is in that location on the keyboard.
///
/// {@tool sample --template=stateful_widget_scaffold}
/// {@tool dartpad --template=stateful_widget_scaffold}
/// This example shows how to detect if the user has selected the logical "Q"
/// key.
///
@@ -331,7 +331,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// looking for "the key next next to the TAB key", since on a French keyboard,
/// the key next to the TAB key has an "A" on it.
///
/// {@tool sample --template=stateful_widget_scaffold}
/// {@tool dartpad --template=stateful_widget_scaffold}
/// This example shows how to detect if the user has selected the physical key
/// to the right of the CAPS LOCK key.
///

View File

@@ -12,40 +12,40 @@
// collide with any currently defined HID codes.
//
// USB HID evdev XKB Win Mac DOMKey Code
USB_KEYMAP(0x05ff01, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton1", BUTTON_1),
USB_KEYMAP(0x05ff02, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton2", BUTTON_2),
USB_KEYMAP(0x05ff03, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton3", BUTTON_3),
USB_KEYMAP(0x05ff04, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton4", BUTTON_4),
USB_KEYMAP(0x05ff05, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton5", BUTTON_5),
USB_KEYMAP(0x05ff06, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton6", BUTTON_6),
USB_KEYMAP(0x05ff07, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton7", BUTTON_7),
USB_KEYMAP(0x05ff08, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton8", BUTTON_8),
USB_KEYMAP(0x05ff09, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton9", BUTTON_9),
USB_KEYMAP(0x05ff0a, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton10", BUTTON_10),
USB_KEYMAP(0x05ff0b, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton11", BUTTON_11),
USB_KEYMAP(0x05ff0c, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton12", BUTTON_12),
USB_KEYMAP(0x05ff0d, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton13", BUTTON_13),
USB_KEYMAP(0x05ff0e, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton14", BUTTON_14),
USB_KEYMAP(0x05ff0f, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton15", BUTTON_15),
USB_KEYMAP(0x05ff10, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton16", BUTTON_16),
USB_KEYMAP(0x05ff11, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonA", BUTTON_A),
USB_KEYMAP(0x05ff12, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonB", BUTTON_B),
USB_KEYMAP(0x05ff13, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonC", BUTTON_C),
USB_KEYMAP(0x05ff14, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonLeft1", BUTTON_L1),
USB_KEYMAP(0x05ff15, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonLeft2", BUTTON_L2),
USB_KEYMAP(0x05ff16, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonMode", BUTTON_MODE),
USB_KEYMAP(0x05ff17, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonRight1", BUTTON_R1),
USB_KEYMAP(0x05ff18, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonRight2", BUTTON_R2),
USB_KEYMAP(0x05ff19, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonSelect", BUTTON_SELECT),
USB_KEYMAP(0x05ff1a, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonStart", BUTTON_START),
USB_KEYMAP(0x05ff1b, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonThumbLeft", BUTTON_THUMBL),
USB_KEYMAP(0x05ff1c, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonThumbRight", BUTTON_THUMBR),
USB_KEYMAP(0x05ff1d, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonX", BUTTON_X),
USB_KEYMAP(0x05ff1e, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonY", BUTTON_Y),
USB_KEYMAP(0x05ff1f, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonZ", BUTTON_Z),
DOM_CODE(0x05ff01, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton1", BUTTON_1),
DOM_CODE(0x05ff02, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton2", BUTTON_2),
DOM_CODE(0x05ff03, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton3", BUTTON_3),
DOM_CODE(0x05ff04, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton4", BUTTON_4),
DOM_CODE(0x05ff05, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton5", BUTTON_5),
DOM_CODE(0x05ff06, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton6", BUTTON_6),
DOM_CODE(0x05ff07, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton7", BUTTON_7),
DOM_CODE(0x05ff08, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton8", BUTTON_8),
DOM_CODE(0x05ff09, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton9", BUTTON_9),
DOM_CODE(0x05ff0a, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton10", BUTTON_10),
DOM_CODE(0x05ff0b, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton11", BUTTON_11),
DOM_CODE(0x05ff0c, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton12", BUTTON_12),
DOM_CODE(0x05ff0d, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton13", BUTTON_13),
DOM_CODE(0x05ff0e, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton14", BUTTON_14),
DOM_CODE(0x05ff0f, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton15", BUTTON_15),
DOM_CODE(0x05ff10, 0x0000, 0x0000, 0x0000, 0xffff, "GameButton16", BUTTON_16),
DOM_CODE(0x05ff11, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonA", BUTTON_A),
DOM_CODE(0x05ff12, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonB", BUTTON_B),
DOM_CODE(0x05ff13, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonC", BUTTON_C),
DOM_CODE(0x05ff14, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonLeft1", BUTTON_L1),
DOM_CODE(0x05ff15, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonLeft2", BUTTON_L2),
DOM_CODE(0x05ff16, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonMode", BUTTON_MODE),
DOM_CODE(0x05ff17, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonRight1", BUTTON_R1),
DOM_CODE(0x05ff18, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonRight2", BUTTON_R2),
DOM_CODE(0x05ff19, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonSelect", BUTTON_SELECT),
DOM_CODE(0x05ff1a, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonStart", BUTTON_START),
DOM_CODE(0x05ff1b, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonThumbLeft", BUTTON_THUMBL),
DOM_CODE(0x05ff1c, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonThumbRight", BUTTON_THUMBR),
DOM_CODE(0x05ff1d, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonX", BUTTON_X),
DOM_CODE(0x05ff1e, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonY", BUTTON_Y),
DOM_CODE(0x05ff1f, 0x0000, 0x0000, 0x0000, 0xffff, "GameButtonZ", BUTTON_Z),
// The Mac defines a key code for the Fn key on Mac keyboards, but it's not
// defined on other platforms. Chromium does define an "Fn" row, but doesn't
// give it a Mac keycode. This overrides their definition.
// USB HID evdev XKB Win Mac DOMKey Code
USB_KEYMAP(0x000012, 0x0000, 0x0000, 0x0000, 0x003f, "Fn", FN),
DOM_CODE(0x000012, 0x0000, 0x0000, 0x0000, 0x003f, "Fn", FN),

View File

@@ -28,32 +28,42 @@ class KeyData {
String androidNameMap,
String glfwKeyCodeHeader,
String glfwNameMap,
String windowsKeyCodeHeader,
String windowsNameMap,
) : assert(chromiumHidCodes != null),
assert(androidKeyboardLayout != null),
assert(androidKeyCodeHeader != null),
assert(androidNameMap != null),
assert(glfwKeyCodeHeader != null),
assert(glfwNameMap != null) {
assert(glfwNameMap != null),
assert(windowsKeyCodeHeader != null),
assert(windowsNameMap != null) {
_nameToAndroidScanCodes = _readAndroidScanCodes(androidKeyboardLayout);
_nameToAndroidKeyCode = _readAndroidKeyCodes(androidKeyCodeHeader);
_nameToGlfwKeyCode = _readGlfwKeyCodes(glfwKeyCodeHeader);
_nameToWindowsKeyCode = _readWindowsKeyCodes(windowsKeyCodeHeader);
// Cast Android dom map
final Map<String, List<dynamic>> dynamicAndroidNames = (json.decode(androidNameMap) as Map<String, List<dynamic>>).cast<String, List<dynamic>>();
final Map<String, List<dynamic>> dynamicAndroidNames = (json.decode(androidNameMap) as Map<String, dynamic>).cast<String, List<dynamic>>();
_nameToAndroidName = dynamicAndroidNames.map<String, List<String>>((String key, List<dynamic> value) {
return MapEntry<String, List<String>>(key, value.cast<String>());
});
// Cast GLFW dom map
final Map<String, List<dynamic>> dynamicGlfwNames = (json.decode(glfwNameMap) as Map<String, List<dynamic>>).cast<String, List<dynamic>>();
final Map<String, List<dynamic>> dynamicGlfwNames = (json.decode(glfwNameMap) as Map<String, dynamic>).cast<String, List<dynamic>>();
_nameToGlfwName = dynamicGlfwNames.map<String, List<String>>((String key, List<dynamic> value) {
return MapEntry<String, List<String>>(key, value.cast<String>());
});
// Cast Windows dom map
final Map<String, List<dynamic>> dynamicWindowsNames = (json.decode(windowsNameMap) as Map<String, dynamic>).cast<String, List<dynamic>>();
_nameToWindowsName = dynamicWindowsNames.map<String, List<String>>((String key, List<dynamic> value) {
return MapEntry<String, List<String>>(key, value.cast<String>());
});
data = _readHidEntries(chromiumHidCodes);
}
/// Parses the given JSON data and populates the data structure from it.
KeyData.fromJson(Map<String, dynamic> contentMap) {
data = <Key>[
for (final String key in contentMap.keys) Key.fromJsonMapEntry(key, contentMap[key] as Map<String, List<dynamic>>),
for (final String key in contentMap.keys) Key.fromJsonMapEntry(key, contentMap[key] as Map<String, dynamic>),
];
}
@@ -86,6 +96,17 @@ class KeyData {
}
}
}
// Windows key names
entry.windowsKeyNames = _nameToWindowsName[entry.constantName]?.cast<String>();
if (entry.windowsKeyNames != null && entry.windowsKeyNames.isNotEmpty) {
for (final String windowsKeyName in entry.windowsKeyNames) {
if (_nameToWindowsKeyCode[windowsKeyName] != null) {
entry.windowsKeyCodes ??= <int>[];
entry.windowsKeyCodes.add(_nameToWindowsKeyCode[windowsKeyName]);
}
}
}
}
final Map<String, dynamic> outputMap = <String, dynamic>{};
@@ -133,6 +154,21 @@ class KeyData {
/// JSON.
Map<String, int> _nameToGlfwKeyCode;
/// The mapping from Widows name (e.g. "RETURN") to the integer key code
/// (logical meaning) of the key.
///
/// Only populated if data is parsed from the source files, not if parsed from
/// JSON.
Map<String, int> _nameToWindowsKeyCode;
/// The mapping from the Flutter name (e.g. "enter") to the Windows name (e.g.
/// "RETURN").
///
/// Only populated if data is parsed from the source files, not if parsed from
/// JSON.
Map<String, List<String>> _nameToWindowsName;
/// Parses entries from Androids Generic.kl scan code data file.
///
/// Lines in this file look like this (without the ///):
@@ -191,9 +227,9 @@ class KeyData {
/// #define GLFW_KEY_SPACE 32,
Map<String, int> _readGlfwKeyCodes(String headerFile) {
// Only get the KEY definitions, ignore the rest (mouse, joystick, etc).
final RegExp enumEntry = RegExp(r'define GLFW_KEY_([A-Z0-9_]+)\s*([A-Z0-9_]+),?');
final RegExp definedCodes = RegExp(r'define GLFW_KEY_([A-Z0-9_]+)\s*([A-Z0-9_]+),?');
final Map<String, dynamic> replaced = <String, dynamic>{};
for (final Match match in enumEntry.allMatches(headerFile)) {
for (final Match match in definedCodes.allMatches(headerFile)) {
replaced[match.group(1)] = int.tryParse(match.group(2)) ?? match.group(2).replaceAll('GLFW_KEY_', '');
}
final Map<String, int> result = <String, int>{};
@@ -208,15 +244,32 @@ class KeyData {
return result;
}
Map<String, int> _readWindowsKeyCodes(String headerFile) {
final RegExp definedCodes = RegExp(r'define VK_([A-Z0-9_]+)\s*([A-Z0-9_x]+),?');
final Map<String, int> replaced = <String, int>{};
for (final Match match in definedCodes.allMatches(headerFile)) {
replaced[match.group(1)] = int.tryParse(match.group(2));
}
// The header doesn't explicitly define the [0-9] and [A-Z], but they mention that the range
// is equivalent to the ASCII value.
for (int i = 0x30; i <= 0x39; i++) {
replaced[String.fromCharCode(i)] = i;
}
for (int i = 0x41; i <= 0x5A; i++) {
replaced[String.fromCharCode(i)] = i;
}
return replaced;
}
/// Parses entries from Chromium's HID code mapping header file.
///
/// Lines in this file look like this (without the ///):
/// USB evdev XKB Win Mac Code Enum
/// USB_KEYMAP(0x000010, 0x0000, 0x0000, 0x0000, 0xffff, "Hyper", HYPER),
/// DOM_CODE(0x000010, 0x0000, 0x0000, 0x0000, 0xffff, "Hyper", HYPER),
List<Key> _readHidEntries(String input) {
final List<Key> entries = <Key>[];
final RegExp usbMapRegExp = RegExp(
r'USB_KEYMAP\s*\(\s*0x([a-fA-F0-9]+),\s*0x([a-fA-F0-9]+),'
r'DOM_CODE\s*\(\s*0x([a-fA-F0-9]+),\s*0x([a-fA-F0-9]+),'
r'\s*0x([a-fA-F0-9]+),\s*0x([a-fA-F0-9]+),\s*0x([a-fA-F0-9]+),\s*"?([^\s]+?)"?,\s*([^\s]+?)\s*\)',
multiLine: true);
final RegExp commentRegExp = RegExp(r'//.*$', multiLine: true);
@@ -270,6 +323,8 @@ class Key {
this.linuxScanCode,
this.xKbScanCode,
this.windowsScanCode,
this.windowsKeyNames,
this.windowsKeyCodes,
this.macOsScanCode,
@required this.chromiumName,
this.androidKeyNames,
@@ -294,6 +349,8 @@ class Key {
linuxScanCode: map['scanCodes']['linux'] as int,
xKbScanCode: map['scanCodes']['xkb'] as int,
windowsScanCode: map['scanCodes']['windows'] as int,
windowsKeyCodes: (map['keyCodes']['windows'] as List<dynamic>)?.cast<int>(),
windowsKeyNames: (map['names']['windows'] as List<dynamic>)?.cast<String>(),
macOsScanCode: map['scanCodes']['macos'] as int,
glfwKeyNames: (map['names']['glfw'] as List<dynamic>)?.cast<String>(),
glfwKeyCodes: (map['keyCodes']['glfw'] as List<dynamic>)?.cast<int>(),
@@ -309,6 +366,13 @@ class Key {
int xKbScanCode;
/// The Windows scan code of the key from Chromium's header file.
int windowsScanCode;
/// The list of Windows key codes matching this key, created by looking up the
/// Windows name in the Chromium data, and substituting the Windows key code
/// value.
List<int> windowsKeyCodes;
/// The list of names that Windows gives to this key (symbol names minus the
/// prefix).
List<String> windowsKeyNames;
/// The macOS scan code of the key from Chromium's header file.
int macOsScanCode;
/// The name of the key, mostly derived from the DomKey name in Chromium,
@@ -347,6 +411,7 @@ class Key {
'english': commentName,
'chromium': chromiumName,
'glfw': glfwKeyNames,
'windows': windowsKeyNames,
},
'scanCodes': <String, dynamic>{
'android': androidScanCodes,
@@ -359,6 +424,7 @@ class Key {
'keyCodes': <String, List<int>>{
'android': androidKeyCodes,
'glfw': glfwKeyCodes,
'windows': windowsKeyCodes,
},
};
}
@@ -420,7 +486,7 @@ class Key {
return """'$constantName': (name: "$name", usbHidCode: ${toHex(usbHidCode)}, """
'linuxScanCode: ${toHex(linuxScanCode)}, xKbScanCode: ${toHex(xKbScanCode)}, '
'windowsKeyCode: ${toHex(windowsScanCode)}, macOsScanCode: ${toHex(macOsScanCode)}, '
'chromiumSymbolName: $chromiumName';
'windowsScanCode: ${toHex(windowsScanCode)}, chromiumSymbolName: $chromiumName';
}
/// Returns the static map of printable representations.

View File

@@ -335,6 +335,11 @@ class LogicalKeyboardKey extends KeyboardKey {
/// See the function [RawKeyEvent.logicalKey] for more information.
static const LogicalKeyboardKey turbo = LogicalKeyboardKey(0x00100000016, debugName: kReleaseMode ? null : 'Turbo');
/// Represents the logical "Privacy Screen Toggle" key on the keyboard.
///
/// See the function [RawKeyEvent.logicalKey] for more information.
static const LogicalKeyboardKey privacyScreenToggle = LogicalKeyboardKey(0x00100000017, debugName: kReleaseMode ? null : 'Privacy Screen Toggle');
/// Represents the logical "Sleep" key on the keyboard.
///
/// See the function [RawKeyEvent.logicalKey] for more information.
@@ -1220,6 +1225,11 @@ class LogicalKeyboardKey extends KeyboardKey {
/// See the function [RawKeyEvent.logicalKey] for more information.
static const LogicalKeyboardKey mediaPlay = LogicalKeyboardKey(0x001000c00b0, debugName: kReleaseMode ? null : 'Media Play');
/// Represents the logical "Media Pause" key on the keyboard.
///
/// See the function [RawKeyEvent.logicalKey] for more information.
static const LogicalKeyboardKey mediaPause = LogicalKeyboardKey(0x001000c00b1, debugName: kReleaseMode ? null : 'Media Pause');
/// Represents the logical "Media Record" key on the keyboard.
///
/// See the function [RawKeyEvent.logicalKey] for more information.
@@ -1663,6 +1673,7 @@ class LogicalKeyboardKey extends KeyboardKey {
0x0100000014: suspend,
0x0100000015: resume,
0x0100000016: turbo,
0x0100000017: privacyScreenToggle,
0x0100010082: sleep,
0x0100010083: wakeUp,
0x01000100b5: displayToggleIntExt,
@@ -1840,6 +1851,7 @@ class LogicalKeyboardKey extends KeyboardKey {
0x01000c009c: channelUp,
0x01000c009d: channelDown,
0x01000c00b0: mediaPlay,
0x01000c00b1: mediaPause,
0x01000c00b2: mediaRecord,
0x01000c00b3: mediaFastForward,
0x01000c00b4: mediaRewind,
@@ -2122,6 +2134,12 @@ class PhysicalKeyboardKey extends KeyboardKey {
/// See the function [RawKeyEvent.physicalKey] for more information.
static const PhysicalKeyboardKey turbo = PhysicalKeyboardKey(0x00000016, debugName: kReleaseMode ? null : 'Turbo');
/// Represents the location of the "Privacy Screen Toggle" key on a
/// generalized keyboard.
///
/// See the function [RawKeyEvent.physicalKey] for more information.
static const PhysicalKeyboardKey privacyScreenToggle = PhysicalKeyboardKey(0x00000017, debugName: kReleaseMode ? null : 'Privacy Screen Toggle');
/// Represents the location of the "Sleep" key on a generalized keyboard.
///
/// See the function [RawKeyEvent.physicalKey] for more information.
@@ -3054,6 +3072,12 @@ class PhysicalKeyboardKey extends KeyboardKey {
/// See the function [RawKeyEvent.physicalKey] for more information.
static const PhysicalKeyboardKey mediaPlay = PhysicalKeyboardKey(0x000c00b0, debugName: kReleaseMode ? null : 'Media Play');
/// Represents the location of the "Media Pause" key on a generalized
/// keyboard.
///
/// See the function [RawKeyEvent.physicalKey] for more information.
static const PhysicalKeyboardKey mediaPause = PhysicalKeyboardKey(0x000c00b1, debugName: kReleaseMode ? null : 'Media Pause');
/// Represents the location of the "Media Record" key on a generalized
/// keyboard.
///
@@ -3536,6 +3560,7 @@ class PhysicalKeyboardKey extends KeyboardKey {
0x00000014: suspend,
0x00000015: resume,
0x00000016: turbo,
0x00000017: privacyScreenToggle,
0x00010082: sleep,
0x00010083: wakeUp,
0x000100b5: displayToggleIntExt,
@@ -3713,6 +3738,7 @@ class PhysicalKeyboardKey extends KeyboardKey {
0x000c009c: channelUp,
0x000c009d: channelDown,
0x000c00b0: mediaPlay,
0x000c00b1: mediaPause,
0x000c00b2: mediaRecord,
0x000c00b3: mediaFastForward,
0x000c00b4: mediaRewind,

View File

@@ -143,6 +143,7 @@ const Map<int, LogicalKeyboardKey> kAndroidToLogicalKey = <int, LogicalKeyboardK
166: LogicalKeyboardKey.channelUp,
167: LogicalKeyboardKey.channelDown,
126: LogicalKeyboardKey.mediaPlay,
127: LogicalKeyboardKey.mediaPause,
130: LogicalKeyboardKey.mediaRecord,
90: LogicalKeyboardKey.mediaFastForward,
89: LogicalKeyboardKey.mediaRewind,
@@ -354,6 +355,7 @@ const Map<int, PhysicalKeyboardKey> kAndroidToPhysicalKey = <int, PhysicalKeyboa
403: PhysicalKeyboardKey.channelDown,
200: PhysicalKeyboardKey.mediaPlay,
207: PhysicalKeyboardKey.mediaPlay,
201: PhysicalKeyboardKey.mediaPause,
167: PhysicalKeyboardKey.mediaRecord,
208: PhysicalKeyboardKey.mediaFastForward,
168: PhysicalKeyboardKey.mediaRewind,
@@ -461,6 +463,7 @@ const Map<int, LogicalKeyboardKey> kFuchsiaToLogicalKey = <int, LogicalKeyboardK
0x100000014: LogicalKeyboardKey.suspend,
0x100000015: LogicalKeyboardKey.resume,
0x100000016: LogicalKeyboardKey.turbo,
0x100000017: LogicalKeyboardKey.privacyScreenToggle,
0x100010082: LogicalKeyboardKey.sleep,
0x100010083: LogicalKeyboardKey.wakeUp,
0x1000100b5: LogicalKeyboardKey.displayToggleIntExt,
@@ -638,6 +641,7 @@ const Map<int, LogicalKeyboardKey> kFuchsiaToLogicalKey = <int, LogicalKeyboardK
0x1000c009c: LogicalKeyboardKey.channelUp,
0x1000c009d: LogicalKeyboardKey.channelDown,
0x1000c00b0: LogicalKeyboardKey.mediaPlay,
0x1000c00b1: LogicalKeyboardKey.mediaPause,
0x1000c00b2: LogicalKeyboardKey.mediaRecord,
0x1000c00b3: LogicalKeyboardKey.mediaFastForward,
0x1000c00b4: LogicalKeyboardKey.mediaRewind,
@@ -731,6 +735,7 @@ const Map<int, PhysicalKeyboardKey> kFuchsiaToPhysicalKey = <int, PhysicalKeyboa
0x00000014: PhysicalKeyboardKey.suspend,
0x00000015: PhysicalKeyboardKey.resume,
0x00000016: PhysicalKeyboardKey.turbo,
0x00000017: PhysicalKeyboardKey.privacyScreenToggle,
0x00010082: PhysicalKeyboardKey.sleep,
0x00010083: PhysicalKeyboardKey.wakeUp,
0x000100b5: PhysicalKeyboardKey.displayToggleIntExt,
@@ -908,6 +913,7 @@ const Map<int, PhysicalKeyboardKey> kFuchsiaToPhysicalKey = <int, PhysicalKeyboa
0x000c009c: PhysicalKeyboardKey.channelUp,
0x000c009d: PhysicalKeyboardKey.channelDown,
0x000c00b0: PhysicalKeyboardKey.mediaPlay,
0x000c00b1: PhysicalKeyboardKey.mediaPause,
0x000c00b2: PhysicalKeyboardKey.mediaRecord,
0x000c00b3: PhysicalKeyboardKey.mediaFastForward,
0x000c00b4: PhysicalKeyboardKey.mediaRewind,
@@ -1103,8 +1109,9 @@ const Map<int, PhysicalKeyboardKey> kMacOsToPhysicalKey = <int, PhysicalKeyboard
0x00000049: PhysicalKeyboardKey.audioVolumeDown,
0x0000005f: PhysicalKeyboardKey.numpadComma,
0x0000005e: PhysicalKeyboardKey.intlRo,
0x00000068: PhysicalKeyboardKey.kanaMode,
0x0000005d: PhysicalKeyboardKey.intlYen,
0x00000068: PhysicalKeyboardKey.lang1,
0x00000066: PhysicalKeyboardKey.lang2,
0x0000003b: PhysicalKeyboardKey.controlLeft,
0x00000038: PhysicalKeyboardKey.shiftLeft,
0x0000003a: PhysicalKeyboardKey.altLeft,
@@ -1305,6 +1312,7 @@ const Map<int, LogicalKeyboardKey> kGlfwNumpadMap = <int, LogicalKeyboardKey>{
/// Maps XKB specific key code values representing [PhysicalKeyboardKey].
const Map<int, PhysicalKeyboardKey> kLinuxToPhysicalKey = <int, PhysicalKeyboardKey>{
0x00000281: PhysicalKeyboardKey.privacyScreenToggle,
0x00000096: PhysicalKeyboardKey.sleep,
0x00000097: PhysicalKeyboardKey.wakeUp,
0x000000eb: PhysicalKeyboardKey.displayToggleIntExt,
@@ -1468,6 +1476,7 @@ const Map<int, PhysicalKeyboardKey> kLinuxToPhysicalKey = <int, PhysicalKeyboard
0x000001a2: PhysicalKeyboardKey.channelUp,
0x000001a3: PhysicalKeyboardKey.channelDown,
0x000000d7: PhysicalKeyboardKey.mediaPlay,
0x000000d1: PhysicalKeyboardKey.mediaPause,
0x000000af: PhysicalKeyboardKey.mediaRecord,
0x000000d8: PhysicalKeyboardKey.mediaFastForward,
0x000000b0: PhysicalKeyboardKey.mediaRewind,
@@ -1528,6 +1537,7 @@ const Map<String, LogicalKeyboardKey> kWebToLogicalKey = <String, LogicalKeyboar
'Suspend': LogicalKeyboardKey.suspend,
'Resume': LogicalKeyboardKey.resume,
'Turbo': LogicalKeyboardKey.turbo,
'PrivacyScreenToggle': LogicalKeyboardKey.privacyScreenToggle,
'Sleep': LogicalKeyboardKey.sleep,
'WakeUp': LogicalKeyboardKey.wakeUp,
'DisplayToggleIntExt': LogicalKeyboardKey.displayToggleIntExt,
@@ -1688,6 +1698,7 @@ const Map<String, LogicalKeyboardKey> kWebToLogicalKey = <String, LogicalKeyboar
'BrightnessUp': LogicalKeyboardKey.brightnessUp,
'BrightnessDown': LogicalKeyboardKey.brightnessDown,
'MediaPlay': LogicalKeyboardKey.mediaPlay,
'MediaPause': LogicalKeyboardKey.mediaPause,
'MediaRecord': LogicalKeyboardKey.mediaRecord,
'MediaFastForward': LogicalKeyboardKey.mediaFastForward,
'MediaRewind': LogicalKeyboardKey.mediaRewind,
@@ -1760,6 +1771,7 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'Suspend': PhysicalKeyboardKey.suspend,
'Resume': PhysicalKeyboardKey.resume,
'Turbo': PhysicalKeyboardKey.turbo,
'PrivacyScreenToggle': PhysicalKeyboardKey.privacyScreenToggle,
'Sleep': PhysicalKeyboardKey.sleep,
'WakeUp': PhysicalKeyboardKey.wakeUp,
'DisplayToggleIntExt': PhysicalKeyboardKey.displayToggleIntExt,
@@ -1920,6 +1932,7 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'BrightnessUp': PhysicalKeyboardKey.brightnessUp,
'BrightnessDown': PhysicalKeyboardKey.brightnessDown,
'MediaPlay': PhysicalKeyboardKey.mediaPlay,
'MediaPause': PhysicalKeyboardKey.mediaPause,
'MediaRecord': PhysicalKeyboardKey.mediaRecord,
'MediaFastForward': PhysicalKeyboardKey.mediaFastForward,
'MediaRewind': PhysicalKeyboardKey.mediaRewind,