logicalKey property

LogicalKeyboardKey logicalKey

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:


LogicalKeyboardKey get logicalKey {
  // If the key has a printable representation, then make a logical key based
  // on that.
  if (codePoint != 0) {
    return LogicalKeyboardKey(
      LogicalKeyboardKey.unicodePlane | codePoint & LogicalKeyboardKey.valueMask,
      keyLabel: keyLabel,
      debugName: kReleaseMode ? null : 'Key $keyLabel',

  // Look to see if the hidUsage is one we know about and have a mapping for.
  LogicalKeyboardKey newKey = kFuchsiaToLogicalKey[hidUsage | LogicalKeyboardKey.hidPlane];
  if (newKey != null) {
    return newKey;

  // This is a non-printable key that we don't know about, so we mint a new
  // code with the autogenerated bit set.
  const int fuchsiaKeyIdPlane = 0x00300000000;
  newKey ??= LogicalKeyboardKey(
    fuchsiaKeyIdPlane | hidUsage | LogicalKeyboardKey.autogeneratedMask,
    debugName: kReleaseMode ? null : 'Ephemeral Fuchsia key code $hidUsage',
  return newKey;