Unverified Commit 0245a29a authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Keycode generation doc fix (#31493)

Fixes a typo in the key generator readme.

Updated the examples in the readme to reflect that the examples were for physical key codes, where we're actually talking about logical key codes there.
parent bc9b56a3
...@@ -56,18 +56,21 @@ checked in. ...@@ -56,18 +56,21 @@ checked in.
## Key Code ID Scheme ## Key Code ID Scheme
In order to provide keys with unique ID codes, Flutter uses a scheme to assign In order to provide logical keys with unique ID codes, Flutter uses a scheme
codes which keeps us out of the business of minting new codes ourselves. to assign logical key codes which keeps us out of the business of minting new
codes ourselves. This only applies to logical key codes: Flutter's
physical key codes are just defined as USB HID codes.
The codes are meant to be opaque to the user, and should never be unpacked for The logical codes are meant to be opaque to the user, and should never be
meaning, since the code scheme could change at any time, and the meaning is unpacked for meaning, since the code scheme could change at any time, and the
likely to be retrievable in a more reliable and correct manner from the API. meaning is likely to be retrievable in a more reliable and correct manner from
the API.
However, if you are porting Flutter to a new platform, you should follow the However, if you are porting Flutter to a new platform, you should follow the
following guidelines for specifying key codes. following guidelines for specifying logical key codes.
The key code is a 37-bit integer in a namespace that we control and define. It The logical key code is a 37-bit integer in a namespace that we control and
has values in the following ranges. define. It has values in the following ranges.
- **0x00 0000 0000 - 0x0 0010 FFFF**: For keys that generate Unicode - **0x00 0000 0000 - 0x0 0010 FFFF**: For keys that generate Unicode
characters when pressed (this includes dead keys, but not e.g. function keys characters when pressed (this includes dead keys, but not e.g. function keys
...@@ -81,9 +84,10 @@ has values in the following ranges. ...@@ -81,9 +84,10 @@ has values in the following ranges.
key in the US layout outputs a q in normal usage, but its code would be 0x0 key in the US layout outputs a q in normal usage, but its code would be 0x0
0000 0051 (U+00051 being the code for the uppercase Q). 0000 0051 (U+00051 being the code for the uppercase Q).
- **0x01 0000 0000 - 0x01 FFFF FFFF**: For keys that are defined by the USB HID - **0x01 0000 0000 - 0x01 FFFF FFFF**: For keys that are defined by the [USB HID
standard, the key code consists of the 32 bit USB extended usage code. For standard](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf),
example, the Enter key would have code 0x0 0007 0028. Only keys that fall the key code consists of the 32 bit USB extended usage code. For
example, the Enter key would have code 0x01 0007 0028. Only keys that fall
into collections "Keyboard", "Keypad", and "Tablet PC System Controls" are into collections "Keyboard", "Keypad", and "Tablet PC System Controls" are
considered for this API; for example, a mixing desk with multiple considered for this API; for example, a mixing desk with multiple
collections of volume controls would not be exposed via DOWN and UP events, collections of volume controls would not be exposed via DOWN and UP events,
...@@ -142,23 +146,21 @@ Here are some examples: ...@@ -142,23 +146,21 @@ Here are some examples:
For example, on a French keyboard layout, pressing CAPS LOCK then pressing For example, on a French keyboard layout, pressing CAPS LOCK then pressing
SHIFT + Y would generate the following sequence: SHIFT + Y would generate the following sequence:
DOWN, code 0x00070039. (CAPS LOCK DOWN)<br> DOWN, code 0x0100070039. (CAPS LOCK DOWN)<br>
UP, code 0x00070039. (CAPS LOCK UP)<br> UP, code 0x0100070039. (CAPS LOCK UP)<br>
DOWN, code 0x000700E1 (SHIFT DOWN)<br> DOWN, code 0x01000700E1 (LEFT SHIFT DOWN)<br>
DOWN, code 0x0007001D, string U+00059 (Y DOWN, the code is for the "Z" key, but DOWN, code 0x0000000059, string U+00059 (Y DOWN)<br>
string is the character, "Y")<br> UP, code 0x0000000059 (Y UP)<br>
UP, code 0x0007001D (Y UP)<br> UP, code 0x01000700E1 (LEFT SHIFT UP)<br>
UP, code 0x000700E1 (SHIFT UP)<br>
Here's another example. On a German keyboard layout, you press ^e (the ^ key is Here's another example. On a German keyboard layout, you press ^e (the ^ key is
at the top left of the keyboard and is a dead key) to produce a “ê”: at the top left of the keyboard and is a dead key) to produce a “ê”:
DOWN, code 0x00070035 (GRAVE DOWN) Assuming that the keymap maps it to the same DOWN, code 0x0000000302 (CIRCUMFLEX DOWN) It produces no string, because it's a dead
logical key, it produces no string, because it's a dead key. The HID key is for key. The key code is for "Combining circumflex accent U+0302" in Unicode.<br>
"Keyboard grave accent and tilde" in AT-101 keyboard typical position 1.<br> UP, code 0x0000000302 (CIRCUMFLEX UP)<br>
UP, code 0x00070035 (GRAVE UP)<br> DOWN, code 0x0000000065, string U+000EA (Unicode for ê‬) (E DOWN).<br>
DOWN, code 0x00070008, string U+000EA (Unicode for ê‬) (E DOWN).<br> UP, code 0x0000000065. (E UP).<br>
UP, code 0x00070008. (E UP).<br>
It is an important point that even though we’re representing many keys with USB It is an important point that even though we’re representing many keys with USB
HID codes, these are not necessarily the same HID codes produced by the hardware HID codes, these are not necessarily the same HID codes produced by the hardware
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment