Physical keyboard events
Fuchsia's Keyboard service provides a mechanism for delivering physical keyboard events to all interested clients.
Rendered Docs
Overview
Key events are delivered only to the components subscribed via Keyboard
FIDL
protocol. Components interested in the service, should list FIDL service in the
components manifest, and it will be injected when the component is started.
Typical use-cases:
- TAB navigation between form fields.
- Arrow keys navigation in menus, lists.
- Pressing “f” to open a File from a menu.
- Closing popups on ESC.
- WASD navigation in games.
Media buttons, shortcuts, and text entry (IME) related events are delivered separately via specialized interfaces.
Key events are only delivered to components in the Scenic focus chain. Only focused components receive key events.
Key events are delivered in root to leaf order - i.e. parent components first.
Parent components have the ability to block further event propagation via
KeyboardListener.OnKeyEvent
by returning KeyEventStatus.Handled
to prevent
event’s propagation.
Clients are notified of keys being pressed or released via Pressed
and
Released
event types.
Clients are notified of keys pressed or released while client wasn't available
(e.g. not focused, or not started) via Sync
and Cancel
event types. Those
events will delivered for relevant events only, e.g. keys pressed and held while
client was not available.
Example
use fidl_fuchsia_ui_input3 as ui_input;
let keyboard = connect_to_protocol::<ui_input::KeyboardMarker>()
.context("Failed to connect to Keyboard service")?;
let (listener_client_end, mut listener_stream) =
create_request_stream::<ui_input::KeyboardListenerMarker>()?;
keyboard.add_listener(view_ref, listener_client_end).await.expect("add_listener");
match listener_stream.next().await {
Some(Ok(ui_input::KeyboardListenerRequest::OnKeyEvent { event, responder, .. })) => {
assert_eq!(event.key, Some(fuchsia_input::Key::A));
responder.send(ui_input::Status::Handled).expect("response from key listener")
},
}
PROTOCOLS
KeyEventInjector
Defined in fuchsia.ui.input3/keyboard.fidl
Provides the ability to inject KeyEvent
s into the keyboard subsystem.
Roles
This protocol will typically be:
- Implemented by platform components which process and deliver keyboard events.
- Consumed by components which originiate keyboard events. E.g. an on-screen keyboard, or the Session Framework Input Pipeline.
Related protocols
This protocol should be using in preference to legacy protocols which provide similar functionality. Specifically, this means this protocol should be preferred over
fuchsia.ui.input.ImeService
which providesInjectInput()
,DispatchKey()
, andDispatchKey3()
fuchsia.ui.input.InputMethodEditor
, which providesInjectInput()
andDispatchKey3()
Notes
Products should take care to limit access to this protocol, as events injected with this protocol are indistinguishable from those coming from physical devices.
Inject
Inject an event into the keyboard subsystem.
Returns
HANDLED
if the keyboard subsystem delivered the event to a consumer, and the consumer reported that itHANDLED
the eventNOT_HANDLED
if the keyboard subsystem did not deliever the event to any consumers, or no consumer reported that itHANDLED
the event.
Request
Name | Type |
---|---|
key_event |
KeyEvent
|
Response
Name | Type |
---|---|
status |
KeyEventStatus
|
Keyboard
Defined in fuchsia.ui.input3/keyboard.fidl
Components may request this service from their namespace to be notified of physical key events.
AddListener
Add a key event listener for the specified View.
If multiple listeners are added, each will receive key events independently and
should respond with a Status
.
The client calling AddListener
should keep the connection to Keyboard
alive
for as long as the events from KeyboardListener
need to be received. Dropping the
connection to the Keyboard
protocol will terminate KeyboardListener
as well.
Request
Name | Type |
---|---|
view_ref |
fuchsia.ui.views/ViewRef
|
listener |
client_end:KeyboardListener
|
Response
<EMPTY>
KeyboardListener
Defined in fuchsia.ui.input3/keyboard.fidl
Client should implement this protocol to get notified of key events.
OnKeyEvent
Called when a key event takes place, such as key press or release.
Protocol implementers must respond to acknowledge the event by returning Status in a timely manner, i.e. not introducing significant delays to the input pipeline (typically 10s of milliseconds).
Returning NOT_HANDLED
means the event may be offered to other
clients of other related APIs.
Clients that do not acknowledge their events will eventually be disconnected.
Notification is only dispatched to a view that has focus. No other views,
including parents or children, will get notified specifically via OnKeyEvent
.
Request
Name | Type |
---|---|
event |
KeyEvent
|
Response
Name | Type |
---|---|
status |
KeyEventStatus
|
ENUMS
KeyEventStatus strict
Type: uint32
Defined in fuchsia.ui.input3/keyboard.fidl
Return type for clients key events listener.
We do not expect new values to be added to this enum.
Name | Value | Description |
---|---|---|
HANDLED |
1 |
The key event was handled and its further propagation should be stopped. |
NOT_HANDLED |
2 |
The key event wasn't handled and should be delivered to other clients or listeners. |
KeyEventType strict
Type: uint32
Defined in fuchsia.ui.input3/events.fidl
Type of the keyboard key input event.
We do not expect new values to be added into this enum.
Name | Value | Description |
---|---|---|
PRESSED |
1 |
Key is actuated. Receiving this event type means that a key has been actuated at the timestamp when the event is received, and while the event recipient is focused. For example, if the key is a keyboard key, then it was just pressed. |
RELEASED |
2 |
Key is no longer actuated. Receiving this event type means that a key has been de-actuated at the timestamp when the event is received, and while the event recipient is focused. For example, if the key is a keyboard key, then it was just released. |
SYNC |
3 |
Key was actuated while the client wasn't able to receive it, and is still actuated now that the client is able to receive key events. This may happen in a few ways:
Therefore, this is not a "regular" key actuation. It reports now that the key has been actuated in the unknown past. Some event recipients may therefore decide that this is not an actionable key event, while some others may decide that it is. For example, recipients that trigger some user action may
decide to ignore |
CANCEL |
4 |
Key may have been actuated, but its actuation has become invalid due to an event other than a key de-actuation. This may happen in a few ways:
Therefore, this is not a "regular" key de-actuation. It reports the key is no longer validly actuated due to an event other than a key release. Some event recipients may therefore decide that this is not an actionable key event, while some others may decide that it is. For example, recipients which trigger some user action may
decide to ignore |
NonPrintableKey flexible
Type: uint32
Defined in fuchsia.ui.input3/events.fidl
NonPrintableKey represents the meaning of a non-symbolic key on a keyboard.
The definition of each key is derived from W3C named values of a key attribute.
API version 9 and onwards
Starting from API version 9, the enum value space is subdivided based on the subsection numbers of the section Named Key Attribute Values, multiplied by 0x1000.
For example, the keys from section 3.10 Multimedia keys will be located
at 0xa000
-0xafff
. The values and reservations that were present
in this enum prior to the introduction of the convention have not been moved,
and values that go logically into pre-existing sections have been inserted
into their logical place using the prior convention (see below). This allows
us to extract the section ranges if this is for some reason useful to the
application.
Prior to API version 9
The space of the nonprintable keys is subdivided roughly to correspond to the subsections of Section 3 of the document Named Key Attribute Values. The choice for the section values is arbitrary, so long as blocks of values are allocated at once, and the keys with similar purpose are kept together.
Reserved ranges
The space of possible values for [NonPrintableKey] is subdivided into a number of ranges, with the intention that the enum values are placed in the appropriate range when added.
- Special keys: 0x00-0x10
- Modifier keys: 0x11-0x30
- Whitespace keys: 0x31-0x40
- Navigation keys: 0x61-0x80
- General-purpose function keys: 0x9000-0x9FFF
Name | Value | Description |
---|---|---|
UNIDENTIFIED |
0 |
This key value is used when an implementation is unable to identify another key value, due to either hardware, platform, or software constraints. Added: 9
|
ALT |
17 |
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. Added: 9
|
ALT_GRAPH |
18 |
The Alternate Graphics (AltGr or AltGraph). This key is used enable the ISO Level 3 shift modifier (the standard Shift key is the level 2 modifier). See ISO9995-1. Added: 9
|
CAPS_LOCK |
19 |
The Caps Lock (Capital) key. Toggle capital character lock function for interpreting subsequent keyboard input event. Added: 9
|
CONTROL |
20 |
The Control or Ctrl key, to enable control modifier function for interpreting concurrent or subsequent keyboard input. Added: 9
|
FN |
21 |
The Function switch Fn key. Activating this key simultaneously with another key changes that key’s value to an alternate character or function. This key is often handled directly in the keyboard hardware and does not usually generate key events. Added: 9
|
FN_LOCK |
22 |
The Function-Lock (FnLock or F-Lock) key. Activating this key switches the mode of the keyboard to changes some keys' values to an alternate character or function. This key is often handled directly in the keyboard hardware and does not usually generate key events. Added: 9
|
META |
23 |
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. Added: 9
|
NUM_LOCK |
24 |
The NumLock or Number Lock key, to toggle numpad mode function for interpreting subsequent keyboard input. Added: 9
|
SCROLL_LOCK |
25 |
The Scroll Lock key, to toggle between scrolling and cursor movement modes. Added: 9
|
SHIFT |
26 |
The Shift key, to enable shift modifier function for interpreting concurrent or subsequent keyboard input. Added: 9
|
SYMBOL |
27 |
The Symbol modifier key (used on some virtual keyboards). Added: 9
|
SYMBOL_LOCK |
28 |
The Symbol Lock key. Added: 9
|
HYPER |
29 |
The Hyper key. A legacy modifier. Added: 9
|
SUPER |
30 |
The Super key. A legacy modifier. Added: 9
|
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 |
Delete the character immediately preceding the cursor (i.e. the character to the left for LTR languages). |
DOWN |
97 |
The down arrow navigation key. |
LEFT |
98 |
The left arrow navigation key. |
RIGHT |
99 |
The right arrow navigation key. |
UP |
100 |
The up arrow navigation key. |
END |
101 |
The "End" key. |
HOME |
102 |
The "Home" key. |
PAGE_DOWN |
103 |
The "Page Down" key. |
PAGE_UP |
104 |
The "Page Up" key. |
ESCAPE |
24581 |
The Added: 10
|
SELECT |
24588 |
The Select key. Used to select the window of a task to focus on. Added: 10
|
BRIGHTNESS_DOWN |
28672 |
The Brightness Down key. Typically controls the display brightness. Added: 10
|
BRIGHTNESS_UP |
28673 |
The Brightness Up key. Typically controls the display brightness. Added: 10
|
F1 |
36865 |
The F1 key, a general purpose function key, as index 1. Added: 9
|
F2 |
36866 |
The F2 key, a general purpose function key, as index 2. Added: 9
|
F3 |
36867 |
The F3 key, a general purpose function key, as index 3. Added: 9
|
F4 |
36868 |
The F4 key, a general purpose function key, as index 4. Added: 9
|
F5 |
36869 |
The F5 key, a general purpose function key, as index 5. Added: 9
|
F6 |
36870 |
The F6 key, a general purpose function key, as index 6. Added: 9
|
F7 |
36871 |
The F7 key, a general purpose function key, as index 7. Added: 9
|
F8 |
36872 |
The F8 key, a general purpose function key, as index 8. Added: 9
|
F9 |
36873 |
The F9 key, a general purpose function key, as index 9. Added: 9
|
F10 |
36874 |
The F10 key, a general purpose function key, as index 10. Added: 9
|
F11 |
36875 |
The F11 key, a general purpose function key, as index 11. Added: 9
|
F12 |
36876 |
The F1 key, a general purpose function key, as index 12. Added: 9
|
SOFT_1 |
36881 |
General purpose virtual function key, as index 1. Added: 9
|
SOFT_2 |
36882 |
General purpose virtual function key, as index 2. Added: 9
|
SOFT_3 |
36883 |
General purpose virtual function key, as index 3. Added: 9
|
SOFT_4 |
36884 |
General purpose virtual function key, as index 4. Added: 9
|
MEDIA_PLAY_PAUSE |
40968 |
Pause the currently playing media. NOTE: Media controller devices should use this value rather than
Added: 10
|
AUDIO_VOLUME_DOWN |
49162 |
Decrease audio volume. Added: 10
|
AUDIO_VOLUME_UP |
49163 |
Increase audio volume. Added: 10
|
AUDIO_VOLUME_MUTE |
49164 |
Toggle between muted state and prior volume level. Added: 10
|
BROWSER_BACK |
61440 |
Navigate to previous content or page in current history. Added: 10
|
BROWSER_FAVORITES |
61441 |
Open the list of browser favorites. Added: 10
|
BROWSER_FORWARD |
61442 |
Navigate to next content or page in current history. Added: 10
|
BROWSER_HOME |
61443 |
Go to the user’s preferred home page. Added: 10
|
BROWSER_REFRESH |
61444 |
Refresh the current page or content. Added: 10
|
BROWSER_SEARCH |
61445 |
Call up the user’s preferred search page. Added: 10
|
BROWSER_STOP |
61446 |
Added: 10
|
ZOOM_TOGGLE |
73799 |
Toggle between full-screen and scaled content, or alter magnification level. Added: 10
|
TABLES
KeyEvent
Defined in fuchsia.ui.input3/events.fidl
A Keyboard event generated to reflect key input. timestamp
and type
are required.
At least one of key
and key_meaning
must be set for a valid event.
Ordinal | Field | Type | Description |
---|---|---|---|
1 |
timestamp |
zx/Time
|
Time in nanoseconds when the event was recorded, in the |
2 |
type |
KeyEventType
|
Type of event. |
3 |
key |
fuchsia.input/Key
|
Identifies the key ignoring modifiers, layout, prior key events, etc. This is called the "physical key" on some platforms. In cases where the key event did not originate from a physical keyboard (e.g. onscreen keyboard) this field may be empty. |
4 |
modifiers |
Modifiers
|
Modifiers in effect at the time of the event. Example: CapsLock is off, user presses CapsLock, then A, then releases both. Event sequence is as follows:
CapsLock is on, user presses CapsLock, then A, then releases both.
|
5 |
key_meaning |
KeyMeaning
|
Meaning of the key. |
6 |
repeat_sequence |
uint32
|
The sequence number of this Unset if this event has been generated in the immediate response to an
input from the keyboard driver. If the |
7 |
lock_state |
LockState
|
The lock state in effect at the time of the event. For example, if CapsLock effect is turned on (pressing 'a' results in the effect 'A'), the corresponding bit in the lock state is set. NOTE: |
8 |
device_id |
uint32
|
Identifies the device originating this event. Added: 24
|
UNIONS
KeyMeaning strict
Defined in fuchsia.ui.input3/events.fidl
The meaning of the key press. This is typically the Unicode codepoint inserted by this event, or an enum representing a key that corresponds to whitespace or is otherwise unprintable.
Ordinal | Variant | Type | Description |
---|---|---|---|
1 |
codepoint |
uint32
|
The Unicode codepoint representing character typed, if any.
|
2 |
non_printable_key |
NonPrintableKey
|
The meaning of the key for key events with no corresponding symbol. |
BITS
LockState flexible
Type: uint64
Defined in fuchsia.ui.input3/modifiers.fidl
A bit field of lock states which are currently active.
Lock state reports whether the lock is active for the keys which have a lock state (need to be pressed once to activate, and one more time to deactivate). A set bit denotes active lock state.
For example, when Caps Lock is active, i.e. pressing 'a' produces the effect
of 'A' appearing on the screen, the CAPS_LOCK
bit will be active.
The bit values in LockState
are chosen to correspond to the values in
Modifiers
, to the extent that this is doable in the long run.
Name | Value | Description |
---|---|---|
CAPS_LOCK |
1 | Applies when the Users should bear in mind that the effect of For example, pressing The position of alphabetic keys may vary depending on the keymap in current use too. |
NUM_LOCK |
2 | Applies when the |
SCROLL_LOCK |
4 | Applies when the |
FUNCTION_LOCK |
8 | Applies when the |
SYMBOL_LOCK |
16 | Applies when the |
Modifiers flexible
Type: uint64
Defined in fuchsia.ui.input3/modifiers.fidl
Declares all the modifiers supported by Fuchsia's input subsystem.
Modifiers are special keys that modify the purpose or the function of other keys when used in combination with them. In the Modifiers type, a bit is set if the specific modifier key is actuated (held down), irrespective of whether the modifier has an associated lock state or not.
NOTE: If you want to examine the lock state (such as whether Caps Lock needs to turn all letters into uppercase),you want [LockState] instead.
Somewhat specially, and as a convenience for the users, the modifiers that have "left" and "right" flavors have special bit values which can be used if the distinction between sides does not matter.
Name | Value | Description |
---|---|---|
CAPS_LOCK |
1 | Applies when the |
NUM_LOCK |
2 | Applies when the |
SCROLL_LOCK |
4 | Applies when the |
FUNCTION |
8 | Applies when the |
SYMBOL |
16 | Applies when the |
LEFT_SHIFT |
32 | Applies when the left SHIFT modifier is actuated. |
RIGHT_SHIFT |
64 | Applies when the right SHIFT modifier is actuated. |
SHIFT |
128 | Applies when either This bit mask a convenience to test for either |
LEFT_ALT |
256 | Applies when the left |
RIGHT_ALT |
512 | Applies when the right |
ALT |
1024 | Applies when either the left |
ALT_GRAPH |
2048 | Applies when the |
LEFT_META |
4096 | Applies when the |
RIGHT_META |
8192 | Applies when the |
META |
16384 | Applies when either |
LEFT_CTRL |
32768 | Applies when the |
RIGHT_CTRL |
65536 | Applies when the |
CTRL |
131072 | Applies when either |