InputBot icon indicating copy to clipboard operation
InputBot copied to clipboard

Passing a lazy_static string slice to KeySequence.send

Open shubhamvasaikar opened this issue 4 years ago • 0 comments

First of all thank you for the efforts you put into this. I am trying to write an application that will send a key sequence when the F2key is pressed. However this string is not known during compile time and I generate it at run time. For this I am using the lazy_static macro to initialize the string during run time. Here's what my code looks like:

lazy_static! {
    pub static ref MY_STRING: String = some_fn().to_string();
}

fn main() {
    println!("{}", MY_STRING.as_str());
    F2Key.bind(|| KeySequence(MY_STRING.as_str()).send());
    handle_input_events();
}

The println line works fine for this, but the KeySequence line does not. I have verified that the binding works well if I just pass it a string literal, however I do not get any output when I pass the static MY_STRING in this way.

The binding is probably working fine, as the program stops and wait instead of just exiting. Other bindings also function. However, it seems that nothing is getting passed to the send() method when ran this way. Any ideas why this might be happening? Thank you.

Edit: I'm running this on a RHEL-8 machine.

shubhamvasaikar avatar May 14 '21 10:05 shubhamvasaikar