fn create_key_event(
    event: &keyboard::KeyboardEvent,
    event_time: input_device::EventTime,
    modifier_state: &keymaps::ModifierState,
) -> fidl_ui_input3::KeyEvent {
    let (key, event_type, modifiers) = (&event.key, event.event_type, event.modifiers);
    fx_log_debug!(
        "ImeHandler::create_key_event: key:{:?}, modifier_state:{:?}, event_type: {:?}",
        key,
        &modifier_state,
        &event_type
    );
    let hid_usage = usages::input3_key_to_hid_usage(*key);
    // TODO(fxbug.dev/73295): Conversion to key meaning should be the task of a keymapper input
    // pipeline stage.  It is not implemented yet.  Until it is, we compute the key meaning based
    // on the US QWERTY key map.
    let key_meaning = match key {
        // Nonprintable keys get their own key meaning.
        fidl_input::Key::Enter => Some(fidl_ui_input3::KeyMeaning::NonPrintableKey(
            fidl_ui_input3::NonPrintableKey::Enter,
        )),
        fidl_input::Key::Tab => {
            Some(fidl_ui_input3::KeyMeaning::NonPrintableKey(fidl_ui_input3::NonPrintableKey::Tab))
        }
        fidl_input::Key::Backspace => Some(fidl_ui_input3::KeyMeaning::NonPrintableKey(
            fidl_ui_input3::NonPrintableKey::Backspace,
        )),
        // Printable keys get code points as key meanings.
        _ => keymaps::hid_usage_to_code_point(hid_usage, modifier_state)
            .map(fidl_ui_input3::KeyMeaning::Codepoint)
            .map_err(|e| {
                fx_log_err!(
                    "ImeHandler::create_key_event: Could not convert HID usage to code point: {:?}, modifiers: {:?}",
                    &hid_usage,
                    modifier_state,
                );
                e
            })
            .ok(),
    };

    fidl_ui_input3::KeyEvent {
        timestamp: Some(event_time.try_into().unwrap_or_default()),
        type_: Some(event_type),
        key: Some(*key),
        modifiers,
        key_meaning,
        ..fidl_ui_input3::KeyEvent::EMPTY
    }
}
/// Returns a KeyEvent with the given parameters.
///
/// # Parameters
/// * `event`: The keyboard event to process.
/// * `event_time`: The time in nanoseconds when the event was first recorded.
/// * `modifier_state`: The state of the monitored modifier keys (e.g. Shift, or CapsLock).
///   Used to determine, for example, whether a key press results in an `a` or an `A`.
Returns a KeyEvent with the given parameters.
Returns a KeyEvent with the given parameters .
fn create_key_event(
    event: &keyboard::KeyboardEvent,
    event_time: input_device::EventTime,
    modifier_state: &keymaps::ModifierState,
) -> fidl_ui_input3::KeyEvent {
    let (key, event_type, modifiers) = (&event.key, event.event_type, event.modifiers);
    fx_log_debug!(
        "ImeHandler::create_key_event: key:{:?}, modifier_state:{:?}, event_type: {:?}",
        key,
        &modifier_state,
        &event_type
    );
    let hid_usage = usages::input3_key_to_hid_usage(*key);
    // TODO(fxbug.dev/73295): Conversion to key meaning should be the task of a keymapper input
    // pipeline stage.  It is not implemented yet.  Until it is, we compute the key meaning based
    // on the US QWERTY key map.
    let key_meaning = match key {
        // Nonprintable keys get their own key meaning.
        fidl_input::Key::Enter => Some(fidl_ui_input3::KeyMeaning::NonPrintableKey(
            fidl_ui_input3::NonPrintableKey::Enter,
        )),
        fidl_input::Key::Tab => {
            Some(fidl_ui_input3::KeyMeaning::NonPrintableKey(fidl_ui_input3::NonPrintableKey::Tab))
        }
        fidl_input::Key::Backspace => Some(fidl_ui_input3::KeyMeaning::NonPrintableKey(
            fidl_ui_input3::NonPrintableKey::Backspace,
        )),
        // Printable keys get code points as key meanings.
        _ => keymaps::hid_usage_to_code_point(hid_usage, modifier_state)
            .map(fidl_ui_input3::KeyMeaning::Codepoint)
            .map_err(|e| {
                fx_log_err!(
                    "ImeHandler::create_key_event: Could not convert HID usage to code point: {:?}, modifiers: {:?}",
                    &hid_usage,
                    modifier_state,
                );
                e
            })
            .ok(),
    };
    fidl_ui_input3::KeyEvent {
        timestamp: Some(event_time.try_into().unwrap_or_default()),
        type_: Some(event_type),
        key: Some(*key),
        modifiers,
        key_meaning,
        ..fidl_ui_input3::KeyEvent::EMPTY
    }
}
fn create_key_event ( event : & keyboard :: KeyboardEvent , event_time : input_device :: EventTime , modifier_state : & keymaps :: ModifierState , ) -> fidl_ui_input3 :: KeyEvent { let ( key , event_type , modifiers ) = ( & event . key , event . event_type , event . modifiers ) ; fx_log_debug ! ( " " key modifier_state event_type ) ; let hid_usage = usages :: input3_key_to_hid_usage ( * key ) ; // TODO(fxbug.dev/73295): Conversion to key meaning should be the task of a keymapper input // pipeline stage.  It is not implemented yet.  Until it is, we compute the key meaning based // on the US QWERTY key map. let key_meaning = match key { // Nonprintable keys get their own key meaning. fidl_input :: Key :: Enter => Some ( fidl_ui_input3 :: KeyMeaning :: NonPrintableKey ( fidl_ui_input3 :: NonPrintableKey :: Enter , ) ) , fidl_input :: Key :: Tab => { Some ( fidl_ui_input3 :: KeyMeaning :: NonPrintableKey ( fidl_ui_input3 :: NonPrintableKey :: Tab ) ) } fidl_input :: Key :: Backspace => Some ( fidl_ui_input3 :: KeyMeaning :: NonPrintableKey ( fidl_ui_input3 :: NonPrintableKey :: Backspace , ) ) , // Printable keys get code points as key meanings. _ => keymaps :: hid_usage_to_code_point ( hid_usage , modifier_state ) . map ( fidl_ui_input3 :: KeyMeaning :: Codepoint ) . map_err ( | e | { fx_log_err ! ( " " hid_usage modifier_state ) ; e } ) . ok ( ) , } ; fidl_ui_input3 :: KeyEvent { timestamp : Some ( event_time . try_into ( ) . unwrap_or_default ( ) ) , type_ : Some ( event_type ) , key : Some ( * key ) , modifiers , key_meaning , .. fidl_ui_input3 :: KeyEvent :: EMPTY } }
Returns a KeyEvent with the given parameters.
Returns a KeyEvent with the given parameters .
event
&keyboard::KeyboardEvent
event_time
input_device::EventTime
modifier_state
&keymaps::ModifierState
event
&keyboard::KeyboardEvent
event_time
input_device::EventTime
modifier_state
&keymaps::ModifierState