/// Converts the `input` string into a key sequence under the provided `InverseKeymap`.
///
/// This is intended for end-to-end and input testing only; for production use cases and general
/// testing, IME injection should be used instead.
///
/// A translation from `input` to a sequence of keystrokes is not guaranteed to exist. If a
/// translation does not exist, `None` is returned.
///
/// The sequence does not contain pauses except between repeated keys or to clear a shift state,
/// though the sequence does terminate with an empty report (no keys pressed). A shift key
/// transition is sent in advance of each series of keys that needs it.
///
/// Note that there is currently no way to distinguish between particular key releases. As such,
/// only one key release report is generated even in combinations, e.g. Shift + A.
///
/// # Examples
///
/// ```
/// # use crate::{keymaps::QWERTY_MAP, inverse_keymap::InverseKeymap};
/// let keymap = InverseKeymap::new(&QWERTY_MAP);
/// let key_sequence = keymap.derive_key_sequence("A").unwrap();
///
/// // [shift, A, clear]
/// assert_eq!(key_sequence.len(), 3);
/// ```
Converts the `input` string into a key sequence under the provided `InverseKeymap`.
This is intended for end-to-end and input testing only; for production use cases and general
testing, IME injection should be used instead.

A translation from `input` to a sequence of keystrokes is not guaranteed to exist. If a
translation does not exist, `None` is returned.

The sequence does not contain pauses except between repeated keys or to clear a shift state,
though the sequence does terminate with an empty report (no keys pressed). A shift key
transition is sent in advance of each series of keys that needs it.

Note that there is currently no way to distinguish between particular key releases. As such,
only one key release report is generated even in combinations, e.g. Shift + A.
Converts the ` input ` string into a key sequence under the provided ` InverseKeymap ` . This is intended for end - to - end and input testing only ; for production use cases and general testing IME injection should be used instead . A translation from ` input ` to a sequence of keystrokes is not guaranteed to exist . If a translation does not exist ` None ` is returned . The sequence does not contain pauses except between repeated keys or to clear a shift state though the sequence does terminate with an empty report ( no keys pressed ) . A shift key transition is sent in advance of each series of keys that needs it . Note that there is currently no way to distinguish between particular key releases . As such only one key release report is generated even in combinations e . g . Shift + A .
pub fn derive_key_sequence(&self, input: &str) -> Option<Vec<KeyboardReport>> {
        let mut reports = vec![];
        let mut shift_pressed = false;
        let mut last_usage = None;
        for ch in input.chars() {
            let key_stroke = self.map.get(&ch)?;
            match key_stroke.shift {
                Shift::Yes if !shift_pressed => {
                    shift_pressed = true;
                    last_usage = Some(0);
                }
                Shift::No if shift_pressed => {
                    shift_pressed = false;
                    last_usage = Some(0);
                }
                _ => {
                    if last_usage == Some(key_stroke.usage) {
                        last_usage = Some(0);
                    }
                }
            }
            if let Some(0) = last_usage {
                reports.push(KeyboardReport {
                    pressed_keys: if shift_pressed {
                        vec![Usages::HidUsageKeyLeftShift as u32]
                    } else {
                        vec![]
                    },
                });
            }
            last_usage = Some(key_stroke.usage);
            reports.push(KeyboardReport {
                pressed_keys: if shift_pressed {
                    vec![key_stroke.usage, Usages::HidUsageKeyLeftShift as u32]
                } else {
                    vec![key_stroke.usage]
                },
            });
        }
        // TODO: In the future, we might want to distinguish between different key releases, instead
        //       of sending one single release report even in the case of key combinations.
        reports.push(KeyboardReport { pressed_keys: vec![] });
        Some(reports)
    }
pub fn derive_key_sequence ( & self , input : & str ) -> Option < Vec < KeyboardReport > > { let mut reports = vec ! [ ] ; let mut shift_pressed = false ; let mut last_usage = None ; for ch in input . chars ( ) { let key_stroke = self . map . get ( & ch ) ? ; match key_stroke . shift { Shift :: Yes if ! shift_pressed => { shift_pressed = true ; last_usage = Some ( 0 ) ; } Shift :: No if shift_pressed => { shift_pressed = false ; last_usage = Some ( 0 ) ; } _ => { if last_usage == Some ( key_stroke . usage ) { last_usage = Some ( 0 ) ; } } } if let Some ( 0 ) = last_usage { reports . push ( KeyboardReport { pressed_keys : if shift_pressed { vec ! [ Usages HidUsageKeyLeftShift as u32 ] } else { vec ! [ ] } , } ) ; } last_usage = Some ( key_stroke . usage ) ; reports . push ( KeyboardReport { pressed_keys : if shift_pressed { vec ! [ key_stroke usage Usages HidUsageKeyLeftShift as u32 ] } else { vec ! [ key_stroke usage ] } , } ) ; } // TODO: In the future, we might want to distinguish between different key releases, instead //       of sending one single release report even in the case of key combinations. reports . push ( KeyboardReport { pressed_keys : vec ! [ ] } ) ; Some ( reports ) }
Converts the `input` string into a key sequence under the provided `InverseKeymap`.
Converts the ` input ` string into a key sequence under the provided ` InverseKeymap ` .
&self
input
&str
examples
None
use crate::{keymaps::qwerty_map, inverse_keymap::inversekeymap};
let keymap = InverseKeymap::new(&QWERTY_MAP);
let key_sequence = keymap.derive_key_sequence("A").unwrap().


let keymap = InverseKeymap :: new ( &QWERTY_MAP ) ; let key_sequence = keymap . derive_key_sequence ( " A " ) . unwrap () .