tree: fc77d3a71d52b855723f8365d1bd4899f73dbced [path history] [tgz]
  1. BUILD.gn
  2. events.fidl
  3. fuchsia.ui.input3.api
  4. fuchsia.ui.input3.api_summary
  5. keyboard.fidl
  6. modifiers.fidl
  7. overview.fidl
  8. README.md
sdk/fidl/fuchsia.ui.input3/README.md

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")
    },
}