fuchsia.ui.input2

PROTOCOLS

Keyboard

Defined in fuchsia.ui.input2/keyboard.fidl

Components may request this service from their namespace to be notified of physical key events.

SetListener

Set key event listener for the specified View.

Request

NameType
view_ref fuchsia.ui.views/ViewRef
listener KeyListener

KeyListener

Defined in fuchsia.ui.input2/keyboard.fidl

Client should implement this protocol to get notified of key events. Returning HANDLED will stop event propagation to other clients. This notification is triggered on the following conditions: 1. Component is focused (ViewRef is on FocusChain) 2. Parent Views get the event first, child views last 3. Client returning HANDLED stops the propagation to subsequent clients

OnKeyEvent

Request

NameType
event KeyEvent

Response

NameType
result Status

KeyboardLayoutState

Defined in fuchsia.ui.input2/layout.fidl

Input method editors should implement this protocol to populate KeyEvent.symbol field based on current key layout.

Watch

Get current key layout. Returns immediately on first call; subsequent calls return when the value changes.

Request

NameType

Response

NameType
layout KeyboardLayout

STRUCTS

PhysicalKeyMapEntry

Defined in fuchsia.ui.input2/layout.fidl

A mapping of a physical key to a key.

NameTypeDescriptionDefault
physical_key Key Physical key that's being mapped. No default
key Key A key to which the physical key is mapped to. No default

SemanticKeyMapEntry

Defined in fuchsia.ui.input2/layout.fidl

A mapping of a key to the semantic meaning.

NameTypeDescriptionDefault
key Key Key that's being mapped. No default
semantic_key SemanticKey Semantic key corresponding to the key. No default

ENUMS

KeyEventPhase

Type: uint32

Defined in fuchsia.ui.input2/events.fidl

Phase of the keyboard key input.

NameValueDescription
PRESSED 0 Key is pressed down.
RELEASED 1 Key is released.

Status

Type: uint32

Defined in fuchsia.ui.input2/keyboard.fidl

Return type for clients key events listener.

NameValueDescription
HANDLED 1
NOT_HANDLED 2

Key

Type: uint32

Defined in fuchsia.ui.input2/keys.fidl

A Fuchsia key represents a control that can be pressed or released such as a button on a keyboard.

Where applicable, the definition of each key is derived from one of the following sources albeit with a Fuchsia-specific numeric value: - USB HID usage codes for usage page 0x0007 (Keyboard/Keypad) - USB HID usage codes for usage page 0x000c (Consumer) - Common but non-standard keys (vendor defined)

The example key mappings included in this documentation assume a US English keyboard layout. Actual behavior varies by layout.

NameValueDescription
A 1 Keyboard a and A Corresponds to USB HID page 0x0007 usage 0x0004
B 2 Keyboard b and B Corresponds to USB HID page 0x0007 usage 0x0005
C 3 Keyboard c and C Corresponds to USB HID page 0x0007 usage 0x0006
D 4 Keyboard d and D Corresponds to USB HID page 0x0007 usage 0x0007
E 5 Keyboard e and E Corresponds to USB HID page 0x0007 usage 0x0008
F 6 Keyboard f and F Corresponds to USB HID page 0x0007 usage 0x0009
G 7 Keyboard g and G Corresponds to USB HID page 0x0007 usage 0x000a
H 8 Keyboard h and H Corresponds to USB HID page 0x0007 usage 0x000b
I 9 Keyboard i and I Corresponds to USB HID page 0x0007 usage 0x000c
J 10 Keyboard j and J Corresponds to USB HID page 0x0007 usage 0x000d
K 11 Keyboard k and K Corresponds to USB HID page 0x0007 usage 0x000e
L 12 Keyboard l and L Corresponds to USB HID page 0x0007 usage 0x000f
M 13 Keyboard m and M Corresponds to USB HID page 0x0007 usage 0x0010
N 14 Keyboard n and N Corresponds to USB HID page 0x0007 usage 0x0011
O 15 Keyboard o and O Corresponds to USB HID page 0x0007 usage 0x0012
P 16 Keyboard p and P Corresponds to USB HID page 0x0007 usage 0x0013
Q 17 Keyboard q and Q Corresponds to USB HID page 0x0007 usage 0x0014
R 18 Keyboard r and R Corresponds to USB HID page 0x0007 usage 0x0015
S 19 Keyboard s and S Corresponds to USB HID page 0x0007 usage 0x0016
T 20 Keyboard t and T Corresponds to USB HID page 0x0007 usage 0x0017
U 21 Keyboard u and U Corresponds to USB HID page 0x0007 usage 0x0018
V 22 Keyboard v and V Corresponds to USB HID page 0x0007 usage 0x0019
W 23 Keyboard w and W Corresponds to USB HID page 0x0007 usage 0x001a
X 24 Keyboard x and X Corresponds to USB HID page 0x0007 usage 0x001b
Y 25 Keyboard y and Y Corresponds to USB HID page 0x0007 usage 0x001c
Z 26 Keyboard z and Z Corresponds to USB HID page 0x0007 usage 0x001d
KEY_1 27 Keyboard 1 and ! Corresponds to USB HID page 0x0007 usage 0x001e
KEY_2 28 Keyboard 2 and @ Corresponds to USB HID page 0x0007 usage 0x001f
KEY_3 29 Keyboard 3 and # Corresponds to USB HID page 0x0007 usage 0x0020
KEY_4 30 Keyboard 4 and $ Corresponds to USB HID page 0x0007 usage 0x0021
KEY_5 31 Keyboard 5 and % Corresponds to USB HID page 0x0007 usage 0x0022
KEY_6 32 Keyboard 6 and ^ Corresponds to USB HID page 0x0007 usage 0x0023
KEY_7 33 Keyboard 7 and & Corresponds to USB HID page 0x0007 usage 0x0024
KEY_8 34 Keyboard 8 and * Corresponds to USB HID page 0x0007 usage 0x0025
KEY_9 35 Keyboard 9 and ( Corresponds to USB HID page 0x0007 usage 0x0026
KEY_0 36 Keyboard 0 and ) Corresponds to USB HID page 0x0007 usage 0x0027
ENTER 37 Keyboard Enter (Return) Corresponds to USB HID page 0x0007 usage 0x0028
ESCAPE 38 Keyboard Escape Corresponds to USB HID page 0x0007 usage 0x0029
BACKSPACE 39 Keyboard Backspace (Backward Delete) Corresponds to USB HID page 0x0007 usage 0x002a
TAB 40 Keyboard Tab Corresponds to USB HID page 0x0007 usage 0x002b
SPACE 41 Keyboard Spacebar Corresponds to USB HID page 0x0007 usage 0x002c
MINUS 42 Keyboard - and (underscore) Corresponds to USB HID page 0x0007 usage 0x002d
EQUALS 43 Keyboard = and + Corresponds to USB HID page 0x0007 usage 0x002e
LEFT_BRACE 44 Keyboard [ and { Corresponds to USB HID page 0x0007 usage 0x002f
RIGHT_BRACE 45 Keyboard ] and } Corresponds to USB HID page 0x0007 usage 0x0030
BACKSLASH 46 Keyboard \ and | Corresponds to USB HID page 0x0007 usage 0x0031
NON_US_HASH 47 Keyboard Non-US # and ~ Corresponds to USB HID page 0x0007 usage 0x0032
SEMICOLON 48 Keyboard ; and : Corresponds to USB HID page 0x0007 usage 0x0033
APOSTROPHE 49 Keyboard ' and " Corresponds to USB HID page 0x0007 usage 0x0034
GRAVE_ACCENT 50 Keyboard Grave Accent and Tilde Corresponds to USB HID page 0x0007 usage 0x0035
COMMA 51 Keyboard , and < Corresponds to USB HID page 0x0007 usage 0x0036
DOT 52 Keyboard . and > Corresponds to USB HID page 0x0007 usage 0x0037
SLASH 53 Keyboard / and ? Corresponds to USB HID page 0x0007 usage 0x0038
CAPS_LOCK 54 Keyboard Caps Lock Corresponds to USB HID page 0x0007 usage 0x0039
F1 55 Keyboard F1 Corresponds to USB HID page 0x0007 usage 0x003a
F2 56 Keyboard F2 Corresponds to USB HID page 0x0007 usage 0x003b
F3 57 Keyboard F3 Corresponds to USB HID page 0x0007 usage 0x003c
F4 58 Keyboard F4 Corresponds to USB HID page 0x0007 usage 0x003d
F5 59 Keyboard F5 Corresponds to USB HID page 0x0007 usage 0x003e
F6 60 Keyboard F6 Corresponds to USB HID page 0x0007 usage 0x003f
F7 61 Keyboard F7 Corresponds to USB HID page 0x0007 usage 0x0040
F8 62 Keyboard F8 Corresponds to USB HID page 0x0007 usage 0x0041
F9 63 Keyboard F9 Corresponds to USB HID page 0x0007 usage 0x0042
F10 64 Keyboard F10 Corresponds to USB HID page 0x0007 usage 0x0043
F11 65 Keyboard F11 Corresponds to USB HID page 0x0007 usage 0x0044
F12 66 Keyboard F12 Corresponds to USB HID page 0x0007 usage 0x0045
PRINT_SCREEN 67 Keyboard Print Screen Corresponds to USB HID page 0x0007 usage 0x0046
SCROLL_LOCK 68 Keyboard Scroll Lock Corresponds to USB HID page 0x0007 usage 0x0047
PAUSE 69 Keyboard Pause Corresponds to USB HID page 0x0007 usage 0x0048
INSERT 70 Keyboard Insert Corresponds to USB HID page 0x0007 usage 0x0049
HOME 71 Keyboard Home Corresponds to USB HID page 0x0007 usage 0x004a
PAGE_UP 72 Keyboard Page Up Corresponds to USB HID page 0x0007 usage 0x004b
DELETE 73 Keyboard Forward Delete Corresponds to USB HID page 0x0007 usage 0x004c
END 74 Keyboard End Corresponds to USB HID page 0x0007 usage 0x004d
PAGE_DOWN 75 Keyboard Page Down Corresponds to USB HID page 0x0007 usage 0x004e
RIGHT 76 Keyboard Right Arrow Corresponds to USB HID page 0x0007 usage 0x004f
LEFT 77 Keyboard Left Arrow Corresponds to USB HID page 0x0007 usage 0x0050
DOWN 78 Keyboard Down Arrow Corresponds to USB HID page 0x0007 usage 0x0051
UP 79 Keyboard Up Arrow Corresponds to USB HID page 0x0007 usage 0x0052
NON_US_BACKSLASH 80 Keyboard Non-US \ and | Corresponds to USB HID page 0x0007 usage 0x0064
LEFT_CTRL 81 Keyboard Left Control Corresponds to USB HID page 0x0007 usage 0x00e0
LEFT_SHIFT 82 Keyboard Left Shift Corresponds to USB HID page 0x0007 usage 0x00e1
LEFT_ALT 83 Keyboard Left Alt Corresponds to USB HID page 0x0007 usage 0x00e2
LEFT_META 84 Keyboard Left GUI (Meta, Windows) Corresponds to USB HID page 0x0007 usage 0x00e3
RIGHT_CTRL 85 Keyboard Right Control Corresponds to USB HID page 0x0007 usage 0x00e4
RIGHT_SHIFT 86 Keyboard Right Shift Corresponds to USB HID page 0x0007 usage 0x00e5
RIGHT_ALT 87 Keyboard Right Alt Corresponds to USB HID page 0x0007 usage 0x00e6
RIGHT_META 88 Keyboard Right GUI (Meta, Windows) Corresponds to USB HID page 0x0007 usage 0x00e7
NUM_LOCK 512 Keypad Num Lock and Clear Corresponds to USB HID page 0x0007 usage 0x0053
KEYPAD_SLASH 513 Keypad / Corresponds to USB HID page 0x0007 usage 0x0054
KEYPAD_ASTERISK 514 Keypad * Corresponds to USB HID page 0x0007 usage 0x0055
KEYPAD_MINUS 515 Keypad - Corresponds to USB HID page 0x0007 usage 0x0056
KEYPAD_PLUS 516 Keypad + Corresponds to USB HID page 0x0007 usage 0x0057
KEYPAD_ENTER 517 Keypad ENTER Corresponds to USB HID page 0x0007 usage 0x0058
KEYPAD_1 518 Keypad 1 and End Corresponds to USB HID page 0x0007 usage 0x0059
KEYPAD_2 519 Keypad 2 and Down Arrow Corresponds to USB HID page 0x0007 usage 0x005a
KEYPAD_3 520 Keypad 3 and Page Down Corresponds to USB HID page 0x0007 usage 0x005b
KEYPAD_4 521 Keypad 4 and Left Arrow Corresponds to USB HID page 0x0007 usage 0x005c
KEYPAD_5 522 Keypad 5 Corresponds to USB HID page 0x0007 usage 0x005d
KEYPAD_6 523 Keypad 6 and Right Arrow Corresponds to USB HID page 0x0007 usage 0x005e
KEYPAD_7 524 Keypad 7 and Home Corresponds to USB HID page 0x0007 usage 0x005f
KEYPAD_8 525 Keypad 8 and Up Arrow Corresponds to USB HID page 0x0007 usage 0x0060
KEYPAD_9 526 Keypad 9 and Page Up Corresponds to USB HID page 0x0007 usage 0x0061
KEYPAD_0 527 Keypad 0 and Insert Corresponds to USB HID page 0x0007 usage 0x0062
KEYPAD_DOT 528 Keypad . and Delete Corresponds to USB HID page 0x0007 usage 0x0063
MEDIA_MUTE 768
MEDIA_VOLUME_INCREMENT 769
MEDIA_VOLUME_DECREMENT 770

SemanticKeyAction

Type: uint32

Defined in fuchsia.ui.input2/semantic_keys.fidl

Semantic Key represents the meaning of a non-symbolic key on a keyboard.

Definition of each key is derived from W3C named values of a key attribute: https://www.w3.org/TR/uievents-key/#named-key-attribute-values

NameValueDescription
ALT 1 The Alt (Alternative) key. This key enables the alternate modifier function for interpreting concurrent or subsequent keyboard input. This key value is also used for the Apple Option key.
ALT_GRAPH 2 The Alternate Graphics (AltGr or AltGraph) key. This key is used enable the ISO Level 3 shift modifier (the standard Shift key is the level 2 modifier). See [ISO9995-1].
CAPS_LOCK 3 The Caps Lock (Capital) key. Toggle capital character lock function for interpreting subsequent keyboard input event.
CONTROL 4 The Control or Ctrl key, to enable control modifier function for interpreting concurrent or subsequent keyboard input.
META 5 The Meta key, to enable meta modifier function for interpreting concurrent or subsequent keyboard input. This key value is used for the Windows Logo key and the Apple Command or ⌘ key.
NUM_LOCK 6 The NumLock or Number Lock key, to toggle numpad mode function for interpreting subsequent keyboard input.
SCROLL_LOCK 7 "ScrollLock" The Scroll Lock key, to toggle between scrolling and cursor movement modes.
SHIFT 8 The Shift key, to enable shift modifier function for interpreting concurrent or subsequent keyboard input.
ARROW_DOWN 33 The down arrow key, to navigate or traverse downward.
ARROW_LEFT 34 The left arrow key, to navigate or traverse leftward.
ARROW_RIGHT 35 The right arrow key, to navigate or traverse rightward.
ARROW_UP 36 The up arrow key, to navigate or traverse upward.
END 37 The End key, used with keyboard entry to go to the end of content.
HOME 38 The Home key, used with keyboard entry, to go to start of content. For the mobile phone Home key (which goes to the phone’s main screen), use "GO_HOME".
PAGE_DOWN 39
PAGE_UP 40
ENTER 49 The Enter or ↵ key, to activate current selection or accept current input. This key value is also used for the Return (Macintosh numpad) key.
TAB 50 The Horizontal Tabulation Tab key.
BACKSPACE 65 The Backspace key. This key value is also used for the key labeled Delete on MacOS keyboards.
DELETE 66 The Delete (Del) Key. This key value is also used for the key labeled Delete on MacOS keyboards when modified by the Fn key.
INSERT 67 The Insert (Ins) key, to toggle between text modes for insertion or overtyping.
F1 97
F2 98
F3 99
F4 100
F5 101
F6 102
F7 103
F8 104
F9 105
F10 106
F11 107
F12 108
CONTEXT_MENU 129 Show the application’s context menu. This key is commonly found between the right Meta key and the right Control key.
ESCAPE 130 The Esc key. This key was originally used to initiate an escape sequence, but is now more generally used to exit or "escape" the current context, such as closing a dialog or exiting full screen mode.
GO_BACK 177 The Back key.
GO_HOME 178 The Home key, which goes to the phone’s main screen.

TABLES

KeyEvent

Defined in fuchsia.ui.input2/events.fidl

Keyboard event is generated to reflect key input.

OrdinalNameTypeDescription
1 key Key The key that was pressed or released, taking the keyboard layout into account. Use this value for the following purposes: - interpreting keyboard shortcuts such as CTRL+C The input system derives this value from `physical_key` by consulting the physical key map of the `KeyboardLayout` that was active for the keyboard when when the key was pressed. Note that the same value will be reported when the key is released even if the keyboard layout changes in the interim between press and release.
2 phase KeyEventPhase Phase of input.
3 modifiers Modifiers Modifier keys being held.
4 semantic_key SemanticKey The semantic meaning of the key that was pressed or released, taking the keyboard layout and modifiers into account. Use this value for the following purposes: - typing text when implementing an input method editor (IME) or when IME services are not available (this won’t work for languages that require composition) The input system derives this value from the combination of `physical_key` and `modifiers` by consulting the key symbol map of `KeyboardLayout` that was active for the keyboard when the key was pressed. Note that the same value will be reported when the key is released even if the keyboard layout or modifiers change in the interim between press and release.
5 physical_key Key Identifies the physical key, ignoring modifiers and layout. Use this value for the following purposes: - applying keyboard layout translations - synthesizing input events into virtual machines, since VMs will do own layout mapping The input system derives this value from the data reported by the keyboard itself without taking into account the keyboard’s current `KeyboardLayout` or modifiers.

KeyboardLayout

Defined in fuchsia.ui.input2/layout.fidl

Collection of key maps.

A physical key is first converted to key using key_map. The key is then used to populate symbol using symbol_map. Maps in KeySymbolMap should be searched for the key mapping in the order they are included. First key mapping found in an applicable map should be used. Only maps with matching modifiers should be used. See KeySymbolMap for modifiers matching criteria and examples.

OrdinalNameTypeDescription
1 key_map PhysicalKeyMap
2 semantic_key_map vector<SemanticKeyMap>[64]

PhysicalKeyMap

Defined in fuchsia.ui.input2/layout.fidl

Key map describes a conversion of a physical key to a key. Physical keys not included here are translated directly into keys.

OrdinalNameTypeDescription
1 entries vector<PhysicalKeyMapEntry>[1024] Collection of keys that should be explicitly mapped.

SemanticKeyMap

Defined in fuchsia.ui.input2/layout.fidl

Key map describes a conversion of a key to symbol representation.

The map should be validated using key event modifier states. Map is applied if every modifier in the 'modifiers' list is active, and all other active modifiers are members of the 'optional_modifiers' list. If a modifier is enabled and not listed in neither modifiers nor optional_modifiers, the map should be ignored.

Example: Keyboard has NumLock and CapsLock enabled, and user presses Shift + Key.A

Map1: modifiers: "CapsLock" optional_modifiers: "NumLock" Map2: modifiers: "Shift", optional_modifiers: "NumLock", "CapsLock", "ScrollLock" Map3: modifiers: None optional_modifiers: "Shift", "CapsLock"

Map1 should be ignored, since "Shift" is pressed but is not included in modifiers or optional_modifiers.

Map2 should be searched, since required "Shift" is enabled, and all other enabled modifiers are included in optional_modifiers.

Map3 should be ignored, since "NumLock" is enabled but not included in modifiers or optional_modifiers.

OrdinalNameTypeDescription
1 modifiers Modifiers Combination of modifiers required for this map to be applied. E.g. if CAPS_LOCK bit is set for this map, the map will be applied if the Caps Lock state is ON. Otherwise this map will be ignored if Caps Lock is off.
2 optional_modifiers Modifiers Combination of modifiers that may be enabled for this map to be applied. E.g. if CAPS_LOCK bit is set for this map, the map will be applied if Caps Lock state is ON. Also it may be applied if Caps Lock is off.
3 entries vector<SemanticKeyMapEntry>[1024] Collection of key to semantic meaning mappings.

XUNIONS

SemanticKey

Defined in fuchsia.ui.input2/events.fidl

Semantic for a physical key typed by the user. For letter or symbolic keys, is a string representation of the key typed. For non-symbolic keys, is a SemanticKeyAction value corresponding to the key pressed.

Examples: Key.A: "a" or "A" in US key layout, depending on CapsLock and Shift Key.SPACE: " " Key.TAB: SemanticKeyAction.TAB Key.GRAVE_ACCENT: "`" or "]" or "<", depending on key layout

NameTypeDescription
symbol string[16] For symbolic keys: string representing character typed.
action SemanticKeyAction For non-symbolic keys: meaning of the key pressed.

BITS

Modifiers

Type: uint32

NameValueDescription
SHIFT 1 Applies when either the `LEFT_SHIFT` or `RIGHT_SHIFT` modifier is pressed.
LEFT_SHIFT 2 Applies when the `LEFT_SHIFT` modifier is pressed.
RIGHT_SHIFT 4 Applies when the `RIGHT_SHIFT` modifier is pressed.
CONTROL 8 Applies when either the `LEFT_CONTROL` or `RIGHT_CONTROL` modifier is pressed.
LEFT_CONTROL 16 Applies when the `LEFT_CONTROL` modifier is pressed.
RIGHT_CONTROL 32 Applies when the `RIGHT_CONTROL` modifier is pressed.
ALT 64 Applies when either the `LEFT_ALT` or `RIGHT_ALT` modifier is pressed.
LEFT_ALT 128 Applies when the `LEFT_ALT` modifier is pressed.
RIGHT_ALT 256 Applies when the `RIGHT_ALT` modifier is pressed.
META 512 Applies when either the `LEFT_META` or `RIGHT_META` modifier is pressed.
LEFT_META 1024 Applies when the `LEFT_META` modifier is pressed.
RIGHT_META 2048 Applies when the `RIGHT_META` modifier is pressed.
CAPS_LOCK 4096 Applies when the `CAPS_LOCK` modifier is locked.
NUM_LOCK 8192 Applies when the `NUM_LOCK` modifier is locked.
SCROLL_LOCK 16384 Applies when the `SCROLL_LOCK` modifier is locked.

CONSTANTS

NameValueTypeDescription
MAX_ENTRIES_PER_MAP 1024 uint64
MAX_MAPS_PER_LAYOUT 64 uint64