[windows] Adds support for keyboard mapping. (#54227)
This commit is contained in:
committed by
GitHub
parent
45bf838014
commit
a0f7f6ca6d
@@ -40,6 +40,7 @@ class KeyEventSimulator {
|
||||
case 'macos':
|
||||
case 'linux':
|
||||
case 'web':
|
||||
case 'windows':
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -62,6 +63,9 @@ class KeyEventSimulator {
|
||||
case 'linux':
|
||||
map = kLinuxToPhysicalKey;
|
||||
break;
|
||||
case 'windows':
|
||||
map = kWindowsToPhysicalKey;
|
||||
break;
|
||||
case 'web':
|
||||
// web doesn't have int type code
|
||||
return null;
|
||||
@@ -95,6 +99,9 @@ class KeyEventSimulator {
|
||||
case 'linux':
|
||||
map = kGlfwToLogicalKey;
|
||||
break;
|
||||
case 'windows':
|
||||
map = kWindowsToLogicalKey;
|
||||
break;
|
||||
}
|
||||
for (final int code in map.keys) {
|
||||
if (key.keyId == map[code].keyId) {
|
||||
@@ -132,6 +139,9 @@ class KeyEventSimulator {
|
||||
case 'web':
|
||||
map = kWebToPhysicalKey;
|
||||
break;
|
||||
case 'windows':
|
||||
map = kWindowsToPhysicalKey;
|
||||
break;
|
||||
}
|
||||
for (final PhysicalKeyboardKey physicalKey in map.values) {
|
||||
if (key.debugName == physicalKey.debugName) {
|
||||
@@ -195,6 +205,12 @@ class KeyEventSimulator {
|
||||
result['code'] = _getWebKeyCode(key);
|
||||
result['key'] = '';
|
||||
result['metaState'] = _getWebModifierFlags(key, isDown);
|
||||
break;
|
||||
case 'windows':
|
||||
result['keyCode'] = keyCode;
|
||||
result['scanCode'] = scanCode;
|
||||
result['characterCodePoint'] = key.keyLabel?.codeUnitAt(0) ?? 0;
|
||||
result['modifiers'] = _getWindowsModifierFlags(key, isDown);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -272,6 +288,59 @@ class KeyEventSimulator {
|
||||
return result;
|
||||
}
|
||||
|
||||
static int _getWindowsModifierFlags(LogicalKeyboardKey newKey, bool isDown) {
|
||||
int result = 0;
|
||||
final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed;
|
||||
if (isDown) {
|
||||
pressed.add(newKey);
|
||||
} else {
|
||||
pressed.remove(newKey);
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.shift)) {
|
||||
result |= RawKeyEventDataWindows.modifierShift;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.shiftLeft)) {
|
||||
result |= RawKeyEventDataWindows.modifierLeftShift;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.shiftRight)) {
|
||||
result |= RawKeyEventDataWindows.modifierRightShift;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.metaLeft)) {
|
||||
result |= RawKeyEventDataWindows.modifierLeftMeta;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.metaRight)) {
|
||||
result |= RawKeyEventDataWindows.modifierRightMeta;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.control)) {
|
||||
result |= RawKeyEventDataWindows.modifierControl;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.controlLeft)) {
|
||||
result |= RawKeyEventDataWindows.modifierLeftControl;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.controlRight)) {
|
||||
result |= RawKeyEventDataWindows.modifierRightControl;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.alt)) {
|
||||
result |= RawKeyEventDataWindows.modifierAlt;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.altLeft)) {
|
||||
result |= RawKeyEventDataWindows.modifierLeftAlt;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.altRight)) {
|
||||
result |= RawKeyEventDataWindows.modifierRightAlt;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.capsLock)) {
|
||||
result |= RawKeyEventDataWindows.modifierCaps;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.numLock)) {
|
||||
result |= RawKeyEventDataWindows.modifierNumLock;
|
||||
}
|
||||
if (pressed.contains(LogicalKeyboardKey.scrollLock)) {
|
||||
result |= RawKeyEventDataWindows.modifierScrollLock;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int _getFuchsiaModifierFlags(LogicalKeyboardKey newKey, bool isDown) {
|
||||
int result = 0;
|
||||
final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed;
|
||||
|
||||
Reference in New Issue
Block a user