Repository navigation
feat: add physical_key to keyboard events and PhysicalKeyboardKey - #7125
Draft
ndonkoHenri wants to merge 1 commit into
Draft
ndonkoHenri wants to merge 1 commit into
ndonkoHenri wants to merge 1 commit into
Conversation
Keyboard events carried only the logical key, which follows the active
layout: on a French AZERTY keyboard the key at the US "W" position types
"Z", so WASD controls in games broke for those users. Events now also
carry the physical key, the key's position on the keyboard.
What changes:
- Client: the page's `keyboard_event` and `KeyboardListener`'s
`key_down`/`key_up`/`key_repeat` send `physical_key`, the key's USB HID
usage code (`PhysicalKeyboardKey.usbHidUsage`). Flutter has no physical
key name outside debug builds, so the code is what identifies the key.
`KeyboardListener` builds the three events in one place.
- `ft.PhysicalKeyboardKey(int, Enum)` has one member per Flutter
`PhysicalKeyboardKey` (269), named like `KeyboardKey` (`W`, `DIGIT_1`,
`ARROW_LEFT`) after the US QWERTY layout and valued with the HID usage
code; `str()` gives the member name.
- `physical_key: Union[PhysicalKeyboardKey, int]` on `KeyboardEvent`,
`KeyDownEvent`, `KeyUpEvent` and `KeyRepeatEvent`: a member for known
keys, the raw code otherwise.
- `generate_keyboard_keys.py` renders both enums into `keyboard_key.py`
from the same Flutter file; `check_unique` guards both against repeated
names or values.
- Docs: `PhysicalKeyboardKey` type page and sidebar entry; the keyboard
shortcuts cookbook page lists `physical_key` and shows a WASD example;
1.2.0 changelog entry.
Tested: a throwaway widget test (not committed) sent an AZERTY press
(logical keyZ, physical keyW) through KeyboardListener and got
`{key: Z, physical_key: 0x0007001A}` for down, repeat and up; Python
decodes that to `KeyboardKey.Z` / `PhysicalKeyboardKey.W` and an unknown
code to a plain int; unit suite passes; generator --verify up to date;
ruff and dart analyze clean. Not run in a live desktop/web client.
ndonkoHenri
force-pushed
the
feat/physical-keyboard-key
branch
from
November 23, 2026 01:53
6301348 to
885eee5
Compare
Deploying flet-website-v2 with
|
| Latest commit: |
885eee5
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1e9cd6b7.flet-website-v2.pages.dev |
| Branch Preview URL: | https://feat-physical-keyboard-key.flet-website-v2.pages.dev |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #7123.
Problem
Keyboard events carry only the logical key, which follows the active layout. On a French AZERTY keyboard the key at the US W position types Z, so WASD controls (games, position-based shortcuts) break for those users, and there's no way to read where a key is.
Change
keyboard_eventandKeyboardListener'skey_down/key_up/key_repeatalso sendphysical_key, the key's USB HID usage code. Flutter'sPhysicalKeyboardKey.debugNameis null in release builds, so the code is what identifies the key.KeyboardListenernow builds its three events in one place.ft.PhysicalKeyboardKey(int, Enum): one member per FlutterPhysicalKeyboardKey(269), named likeKeyboardKeyafter the US QWERTY layout (W,DIGIT_1,ARROW_LEFT), valued with the HID code;str()gives the member name.physical_key: Union[PhysicalKeyboardKey, int]onKeyboardEvent,KeyDownEvent,KeyUpEventandKeyRepeatEvent; a key without a member is its raw code.generate_keyboard_keys.pyrenders both enums intokeyboard_key.pyfrom the same Flutter file, so the existing CI--verifystep covers both.PhysicalKeyboardKeytype page; the keyboard shortcuts cookbook page listsphysical_keyand has a WASD example.Testing
keyZ, physicalkeyW) throughKeyboardListener: down, repeat and up each delivered{key: "Z", physical_key: 0x0007001A}.KeyboardKey.Z/PhysicalKeyboardKey.W, and an unknown code to a plainint.--verifyup to date; ruff anddart analyzeclean.Summary by Sourcery
Add physical keyboard key support so applications can distinguish a key’s position from the character produced by the active layout.
New Features:
physical_keyproperty.PhysicalKeyboardKeyvalues for USB HID key usages, with unknown usages preserved as integers.Enhancements:
Documentation:
PhysicalKeyboardKeyand demonstrate layout-independent WASD handling in the keyboard shortcuts guide.Chores: