pub fn string_to_hid_packets(layout_key: &str, string: &str) -> Result<Bytes, Error> {
    let keys_and_modifiers = string_to_keys_and_modifiers(layout_key, string)?;

    debug!("Keys and Modifiers for {}:{:?}", string, keys_and_modifiers);
    let mut packet_bytes = BytesMut::with_capacity(HID_PACKET_LEN * keys_and_modifiers.len() * 2);

    for KeyMod {
        key,
        modifier,
        release,
    } in keys_and_modifiers.iter()
    {
        packet_bytes.put_u8(*modifier);
        packet_bytes.put_u8(0u8);
        packet_bytes.put_u8(*key);
        packet_bytes.put_slice(&HID_PACKET_SUFFIX);
        match *release {
            Release::All => packet_bytes.put_slice(&RELEASE_KEYS_HID_PACKET),
            Release::Keys => {
                packet_bytes.put_u8(*modifier);
                packet_bytes.put_u8(0u8);
                packet_bytes.put_u8(0u8);
                packet_bytes.put_slice(&HID_PACKET_SUFFIX);
            }
            Release::None => {}
        }
    }

    Ok(packet_bytes.freeze())
}
/// Create the sequence of HID packets required to type the given string. Impersonating a keyboard
/// with the specified layout. These packets can be written directly to a HID device file.
Create the sequence of HID packets required to type the given string. Impersonating a keyboard
with the specified layout. These packets can be written directly to a HID device file.
Create the sequence of HID packets required to type the given string . Impersonating a keyboard with the specified layout . These packets can be written directly to a HID device file .
pub fn string_to_hid_packets(layout_key: &str, string: &str) -> Result<Bytes, Error> {
    let keys_and_modifiers = string_to_keys_and_modifiers(layout_key, string)?;
    debug!("Keys and Modifiers for {}:{:?}", string, keys_and_modifiers);
    let mut packet_bytes = BytesMut::with_capacity(HID_PACKET_LEN * keys_and_modifiers.len() * 2);
    for KeyMod {
        key,
        modifier,
        release,
    } in keys_and_modifiers.iter()
    {
        packet_bytes.put_u8(*modifier);
        packet_bytes.put_u8(0u8);
        packet_bytes.put_u8(*key);
        packet_bytes.put_slice(&HID_PACKET_SUFFIX);
        match *release {
            Release::All => packet_bytes.put_slice(&RELEASE_KEYS_HID_PACKET),
            Release::Keys => {
                packet_bytes.put_u8(*modifier);
                packet_bytes.put_u8(0u8);
                packet_bytes.put_u8(0u8);
                packet_bytes.put_slice(&HID_PACKET_SUFFIX);
            }
            Release::None => {}
        }
    }
    Ok(packet_bytes.freeze())
}
pub fn string_to_hid_packets ( layout_key : & str , string : & str ) -> Result < Bytes , Error > { let keys_and_modifiers = string_to_keys_and_modifiers ( layout_key , string ) ? ; debug ! ( " " string keys_and_modifiers ) ; let mut packet_bytes = BytesMut :: with_capacity ( HID_PACKET_LEN * keys_and_modifiers . len ( ) * 2 ) ; for KeyMod { key , modifier , release , } in keys_and_modifiers . iter ( ) { packet_bytes . put_u8 ( * modifier ) ; packet_bytes . put_u8 ( 0u8 ) ; packet_bytes . put_u8 ( * key ) ; packet_bytes . put_slice ( & HID_PACKET_SUFFIX ) ; match * release { Release :: All => packet_bytes . put_slice ( & RELEASE_KEYS_HID_PACKET ) , Release :: Keys => { packet_bytes . put_u8 ( * modifier ) ; packet_bytes . put_u8 ( 0u8 ) ; packet_bytes . put_u8 ( 0u8 ) ; packet_bytes . put_slice ( & HID_PACKET_SUFFIX ) ; } Release :: None => { } } } Ok ( packet_bytes . freeze ( ) ) }
Create the sequence of HID packets required to type the given string.
Create the sequence of HID packets required to type the given string .
layout_key
&str
string
&str
layout_key
&str
string
&str