logicalKey property
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 key based on location. Typically they are
// numpad keys (versus main area keys) and left/right modifiers.
final LogicalKeyboardKey? maybeLocationKey = kWebLocationMap[key]?[location];
if (maybeLocationKey != null) {
return maybeLocationKey;
}
// Look to see if the [key] is one we know about and have a mapping for.
final LogicalKeyboardKey? newKey = kWebToLogicalKey[key];
if (newKey != null) {
return newKey;
}
final bool isPrintable = key.length == 1;
if (isPrintable) {
return LogicalKeyboardKey(key.toLowerCase().codeUnitAt(0));
}
// This is a non-printable key that we don't know about, so we mint a new
// key from `code`. Don't mint with `key`, because the `key` will always be
// "Unidentified" .
return LogicalKeyboardKey(code.hashCode + LogicalKeyboardKey.webPlane);
}