physicalKey property

PhysicalKeyboardKey physicalKey

Returns an object representing the physical location of this key.

A PhysicalKeyboardKey represents a USB HID code sent from the keyboard, ignoring the key map, modifier keys (like SHIFT), and the label on the key.

PhysicalKeyboardKeys are used to describe and test for keys in a particular location. A PhysicalKeyboardKey may have a name, but the name is a mnemonic ("keyA" is easier to remember than 0x70004), derived from the key's effect on a QWERTY keyboard. The name does not represent the key's effect whatsoever (a physical "keyA" can be the Q key on an AZERTY keyboard).

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 a physical key 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 an AZERTY 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 KeyEvent.logicalKey instead.

Also, even though physical keys are defined with USB HID codes, their values are not necessarily the same HID codes produced by the hardware and presented to the driver. On most platforms, Flutter has to map the platform representation back to a HID code because the original HID code is not provided. USB HID was chosen because it is a well-defined standard for referring to keys such as those a Flutter app may encounter.

See also:

  • logicalKey for the non-location specific key generated by this event.
  • character for the character generated by this keypress (if any).


final PhysicalKeyboardKey physicalKey;