Skip to content

Commit 96813e9

Browse files
authored
[gen_keycodes] Clarify the README that the code scheme also applies to physical keys (#106078)
* Impl * Revert some changes * More doc changes * Remove legacy code
1 parent 8e8a1c8 commit 96813e9

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

dev/tools/gen_keycodes/README.md

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
This directory contains a keycode generator that can generate Dart code for
44
the `LogicalKeyboardKey` and `PhysicalKeyboardKey` classes.
55

6-
It generates multiple files across Flutter. For framework, it generates
6+
It generates multiple files across Flutter. For framework, it generates
77

88
* [`keyboard_key.dart`](../../../packages/flutter/lib/src/services/keyboard_key.dart), which contains the definition and list of logical keys and physical keys; and
99
* [`keyboard_maps.dart`](../../../packages/flutter/lib/src/services/keyboard_maps.dart), which contains platform-specific immutable maps used for the `RawKeyboard` API.
1010

11-
For engine, it generates one key mapping file for each platform.
11+
For engine, it generates one key mapping file for each platform, as well as some
12+
files for testing purposes.
1213

1314
It draws information from various source bases, including online
14-
repositories, and manual mapping in the `data` subdirectory. It incorporates
15+
repositories, and manual mapping in the `data` subdirectory. It incorporates
1516
this information into a giant list of physical keys
1617
([`physical_key_data.json`](data/physical_key_data.json)),
1718
and another for logical keys
@@ -38,46 +39,45 @@ This will generate `physical_key_data.json` and `logical_key_data.json`. These
3839
files should be checked in.
3940

4041
By default this tool assumes that the gclient directory for flutter/engine
41-
and the root for the flutter/flutter are placed at the same folder. If not,
42+
and the root for the flutter/flutter are placed at the same folder. If not,
4243
use `--engine-root=/ENGINE/GCLIENT/ROOT` to specify the engine root.
4344

4445
Other options can be found using `--help`.
4546

46-
## Logical Key ID Scheme
47+
## Key ID Scheme
4748

48-
To provide logical keys with unique ID codes, Flutter uses a scheme
49-
to assign logical keycodes which keeps us out of the business of minting new
50-
codes ourselves. This only applies to logical key codes: Flutter's
51-
physical key codes are just defined as USB HID codes.
49+
To provide keys with unique ID codes, Flutter uses a scheme to assign keycodes
50+
which keeps us out of the business of minting new codes ourselves. This applies
51+
both logical keys and physical keys.
5252

53-
The logical codes are meant to be opaque to the user, and should never be
54-
unpacked for meaning, since the coding scheme could change at any time and the
55-
meaning is likely to be retrievable more reliably and correctly from
56-
the API.
53+
The codes are meant to be opaque to the user, and should never be unpacked for
54+
meaning, since the coding scheme could change at any time and the meaning is
55+
likely to be retrievable more reliably and correctly from the API.
5756

5857
However, if you are porting Flutter to a new platform, you should follow the
59-
following guidelines for specifying logical key codes.
58+
following guidelines for specifying key codes.
6059

61-
The logical key code is a 52-bit integer (due to the limitation of JavaScript).
62-
The entire namespace is divided into 32-bit *planes*. The upper 20 bits of the
63-
ID represent the plane ID, while the lower 32 bits represent values in the
64-
plane. For example, plane 0x1 refers to the range 0x1 0000 0000 -
65-
0x1 FFFF FFFF. Each plane manages how the values within the range are assigned.
60+
The key code is a 52-bit integer (due to the limitation of JavaScript). The
61+
entire namespace is divided into 32-bit *planes*. The upper 20 bits of the ID
62+
represent the plane ID, while the lower 32 bits represent values in the plane.
63+
For example, plane 0x1 refers to the range 0x1 0000 0000 - 0x1 FFFF FFFF. Each
64+
plane manages how the values within the range are assigned.
6665

6766
The planes are planned as follows:
6867

69-
- **Plane 0x00**: The Unicode plane. This plane contains keys that generate Unicode
70-
characters when pressed (this includes dead keys, but not e.g. function keys
71-
or shift keys). The value is defined as the Unicode code point corresponding
72-
to the character, lower case and without modifier keys if possible.
73-
Examples are Key A (0x61), Digit 1 (0x31), Colon (0x3A), and Key Ù (0xD9).
74-
(The "Colon" key represents a keyboard key that prints the ":"
75-
character without modifiers, which can be found on the French layout. On the
76-
US layout, the key that prints ":" is the Semicolon key.)
77-
This plane also contains key None (0x0).
78-
79-
- **Plane 0x01**: The unprintable plane. This plane contains keys that are defined
80-
by the [Chromium key list](https://chromium.googlesource.com/codesearch/chromium/src/+/refs/heads/master/ui/events/keycodes/dom/dom_key_data.inc)
68+
- **Plane 0x00**: The Unicode plane. For logical keys, this plane contains keys
69+
that generate Unicode characters when pressed (this includes dead keys, but
70+
not e.g. function keys or shift keys). The value is defined as the Unicode
71+
code point corresponding to the character, lower case and without modifier
72+
keys if possible. Examples are Key A (0x61), Digit 1 (0x31), Colon (0x3A),
73+
and Key Ù (0xD9). (The "Colon" key represents a keyboard key that prints the
74+
":" character without modifiers, which can be found on the French layout. On
75+
the US layout, the key that prints ":" is the Semicolon key.) For physical
76+
keys, this plane contains keys from USB HID usages.
77+
78+
- **Plane 0x01**: The unprintable plane. This plane contains logical keys that
79+
are defined by the [Chromium key
80+
list](https://chromium.googlesource.com/codesearch/chromium/src/+/refs/heads/master/ui/events/keycodes/dom/dom_key_data.inc)
8181
and do not generate Unicode characters. The value is defined as the macro
8282
value defined by the Chromium key list. Examples are CapsLock (0x105),
8383
ArrowUp (0x304), F1 (0x801), Hiragata (0x716), and TVPower (0xD4B).
@@ -86,11 +86,10 @@ The planes are planned as follows:
8686
information.
8787

8888
- **Plane 0x02**: The Flutter plane. This plane contains keys that are
89-
defined by Flutter. The values are also manually assigned by Flutter.
90-
Modifier keys are placed in this plane, because Flutter distinguishes
91-
between sided modifier keys (for example "ShiftLeft" and "ShiftRight"),
92-
while the web doesn't (only has "Shift").
93-
Other examples are numpad keys and gamepad keys.
89+
defined by Flutter. Modifier keys are placed in this plane, because Flutter
90+
distinguishes between sided modifier keys (for example "ShiftLeft" and
91+
"ShiftRight"), while the web doesn't (only has "Shift"). Other examples are
92+
numpad keys and gamepad keys.
9493

9594
- **Plane 0x03-0x0F**: Reserved.
9695

@@ -114,8 +113,7 @@ The planes are planned as follows:
114113
recognized by Flutter.
115114

116115
The value scheme within a platform plane is decided by the platform,
117-
typically using the field from the platform's native key event that
118-
represents the key's logical effect (such as `keycode`, `virtual key`, etc).
116+
typically using the other fields from the platform's native key event.
119117

120118
In time, keys that originally belong to a platform plane might be added to
121119
Flutter, especially if a key is found shared by multiple platforms. The values
@@ -129,5 +127,5 @@ The planes are planned as follows:
129127
to use the platform-plane value to avoid adding platform-exclusive values
130128
to the framework.
131129

132-
- **Plane 0x20-0x2F**: Custom platform planes. Similar to Flutter's platform
130+
- **Plane 0x20-0x2F**: Custom platform planes. Similar to Flutter's platform
133131
planes, but for private use by custom platforms.

0 commit comments

Comments
 (0)