physicalKey property
Returns an object representing the physical location of this key on a QWERTY keyboard.
The PhysicalKeyboardKey ignores the key map, modifier keys (like SHIFT), and the label on the key. It describes the location of the key as if it were on a QWERTY keyboard regardless of the keyboard mapping in effect.
PhysicalKeyboardKeys are used to describe and test for keys in a particular location.
For instance, if you wanted to make a game where the key to the right of the CAPS LOCK key made the player move left, you would be comparing the result of this physicalKey with PhysicalKeyboardKey.keyA, since that is the key next to the CAPS LOCK key on a QWERTY keyboard. This would return the same thing even on a French keyboard where the key next to the CAPS LOCK produces a "Q" when pressed.
If you want to make your app respond to a key with a particular character on it regardless of location of the key, use RawKeyEvent.logicalKey instead.
See also:
- logicalKey for the non-location-specific key generated by this event.
- RawKeyEvent.physicalKey, where this value is available on the event.
Implementation
@override
PhysicalKeyboardKey get physicalKey {
if (kAndroidToPhysicalKey.containsKey(scanCode)) {
return kAndroidToPhysicalKey[scanCode]!;
}
// Android sends DPAD_UP, etc. as the keyCode for joystick DPAD events, but
// it doesn't set the scanCode for those, so we have to detect this, and set
// our own DPAD physical keys. The logical key will still match "arrowUp",
// etc.
if (eventSource & _sourceJoystick == _sourceJoystick) {
final LogicalKeyboardKey? foundKey = kAndroidToLogicalKey[keyCode];
if (foundKey == LogicalKeyboardKey.arrowUp) {
return PhysicalKeyboardKey.arrowUp;
}
if (foundKey == LogicalKeyboardKey.arrowDown) {
return PhysicalKeyboardKey.arrowDown;
}
if (foundKey == LogicalKeyboardKey.arrowLeft) {
return PhysicalKeyboardKey.arrowLeft;
}
if (foundKey == LogicalKeyboardKey.arrowRight) {
return PhysicalKeyboardKey.arrowRight;
}
}
return PhysicalKeyboardKey(LogicalKeyboardKey.androidPlane + scanCode);
}