pub fn string_to_keys_and_modifiers(layout_key: &str, string: &str) -> Result<Vec<KeyMod>, Error> {
    let layout = LAYOUT_MAP
        .get(layout_key)
        .ok_or_else(|| Error::InvalidLayoutKey(layout_key.to_string()))?;

    let mut keys_and_modifiers: Vec<KeyMod> = Vec::with_capacity(string.len());

    for c in string.chars() {
        match keycode_for_unicode(layout, c as u16) {
            Keycode::ModifierKeySequence(modifier, sequence) => {
                for keycode in sequence {
                    keys_and_modifiers.push(KeyMod {
                        key: keycode as u8,
                        modifier: modifier as u8,
                        release: Release::Keys,
                    });
                }
                // Manually add release after sequence is finished
                keys_and_modifiers.push(KeyMod {
                    key: 0,
                    modifier: 0,
                    release: Release::None,
                });
            }
            Keycode::RegularKey(keycode) => {
                if let Some(dead_keycode) = deadkey_for_keycode(layout, keycode) {
                    let key = key_for_keycode(layout, dead_keycode);
                    let modifier = modifier_for_keycode(layout, dead_keycode);
                    keys_and_modifiers.push(KeyMod {
                        key,
                        modifier,
                        release: Release::All,
                    });
                }
                let key = key_for_keycode(layout, keycode);
                let modifier = modifier_for_keycode(layout, keycode);
                keys_and_modifiers.push(KeyMod {
                    key,
                    modifier,
                    release: Release::All,
                });
            }
            _ => return Err(Error::InvalidCharacter(c)),
        }
    }

    Ok(keys_and_modifiers)
}
/// Get a list of the key and modifier pairs required to type the given string on a keyboard with
/// the specified layout.
Get a list of the key and modifier pairs required to type the given string on a keyboard with
the specified layout.
Get a list of the key and modifier pairs required to type the given string on a keyboard with the specified layout .
pub fn string_to_keys_and_modifiers(layout_key: &str, string: &str) -> Result<Vec<KeyMod>, Error> {
    let layout = LAYOUT_MAP
        .get(layout_key)
        .ok_or_else(|| Error::InvalidLayoutKey(layout_key.to_string()))?;
    let mut keys_and_modifiers: Vec<KeyMod> = Vec::with_capacity(string.len());
    for c in string.chars() {
        match keycode_for_unicode(layout, c as u16) {
            Keycode::ModifierKeySequence(modifier, sequence) => {
                for keycode in sequence {
                    keys_and_modifiers.push(KeyMod {
                        key: keycode as u8,
                        modifier: modifier as u8,
                        release: Release::Keys,
                    });
                }
                // Manually add release after sequence is finished
                keys_and_modifiers.push(KeyMod {
                    key: 0,
                    modifier: 0,
                    release: Release::None,
                });
            }
            Keycode::RegularKey(keycode) => {
                if let Some(dead_keycode) = deadkey_for_keycode(layout, keycode) {
                    let key = key_for_keycode(layout, dead_keycode);
                    let modifier = modifier_for_keycode(layout, dead_keycode);
                    keys_and_modifiers.push(KeyMod {
                        key,
                        modifier,
                        release: Release::All,
                    });
                }
                let key = key_for_keycode(layout, keycode);
                let modifier = modifier_for_keycode(layout, keycode);
                keys_and_modifiers.push(KeyMod {
                    key,
                    modifier,
                    release: Release::All,
                });
            }
            _ => return Err(Error::InvalidCharacter(c)),
        }
    }
    Ok(keys_and_modifiers)
}
pub fn string_to_keys_and_modifiers ( layout_key : & str , string : & str ) -> Result < Vec < KeyMod > , Error > { let layout = LAYOUT_MAP . get ( layout_key ) . ok_or_else ( | | Error :: InvalidLayoutKey ( layout_key . to_string ( ) ) ) ? ; let mut keys_and_modifiers : Vec < KeyMod > = Vec :: with_capacity ( string . len ( ) ) ; for c in string . chars ( ) { match keycode_for_unicode ( layout , c as u16 ) { Keycode :: ModifierKeySequence ( modifier , sequence ) => { for keycode in sequence { keys_and_modifiers . push ( KeyMod { key : keycode as u8 , modifier : modifier as u8 , release : Release :: Keys , } ) ; } // Manually add release after sequence is finished keys_and_modifiers . push ( KeyMod { key : 0 , modifier : 0 , release : Release :: None , } ) ; } Keycode :: RegularKey ( keycode ) => { if let Some ( dead_keycode ) = deadkey_for_keycode ( layout , keycode ) { let key = key_for_keycode ( layout , dead_keycode ) ; let modifier = modifier_for_keycode ( layout , dead_keycode ) ; keys_and_modifiers . push ( KeyMod { key , modifier , release : Release :: All , } ) ; } let key = key_for_keycode ( layout , keycode ) ; let modifier = modifier_for_keycode ( layout , keycode ) ; keys_and_modifiers . push ( KeyMod { key , modifier , release : Release :: All , } ) ; } _ => return Err ( Error :: InvalidCharacter ( c ) ) , } } Ok ( keys_and_modifiers ) }
Get a list of the key and modifier pairs required to type the given string on a keyboard with
the specified layout.
Get a list of the key and modifier pairs required to type the given string on a keyboard with the specified layout .
layout_key
&str
string
&str
layout_key
&str
string
&str