logicalKey property Null safety
override
Returns an object representing the logical key that was pressed.
This method takes into account the key map and modifier keys (like SHIFT) to determine which logical key to return.
If you are looking for the character produced by a key event, use RawKeyEvent.character instead.
If you are collecting text strings, use the TextField or CupertinoTextField widgets, since those automatically handle many of the complexities of managing keyboard input, like showing a soft keyboard or interacting with an input method editor (IME).
See also:
- physicalKey for the location-specific key generated by this event.
- RawKeyEvent.logicalKey, where this value is available on the event.
Implementation
@override
LogicalKeyboardKey get logicalKey {
// Look to see if the keyCode is a printable number pad key, so that a
// difference between regular keys (e.g. "=") and the number pad version
// (e.g. the "=" on the number pad) can be determined.
final LogicalKeyboardKey? numPadKey = kAndroidNumPadMap[keyCode];
if (numPadKey != null) {
return numPadKey;
}
// If it has a non-control-character label, then either return the existing
// constant, or construct a new Unicode-based key from it. Don't mark it as
// autogenerated, since the label uniquely identifies an ID from the Unicode
// plane.
if (keyLabel.isNotEmpty && !LogicalKeyboardKey.isControlCharacter(keyLabel)) {
final int combinedCodePoint = plainCodePoint & _kCombiningCharacterMask;
final int keyId = LogicalKeyboardKey.unicodePlane | (combinedCodePoint & LogicalKeyboardKey.valueMask);
return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey(keyId);
}
// Look to see if the keyCode is one we know about and have a mapping for.
final LogicalKeyboardKey? newKey = kAndroidToLogicalKey[keyCode];
if (newKey != null) {
return newKey;
}
return LogicalKeyboardKey(keyCode | LogicalKeyboardKey.androidPlane);
}