key_sequences/key_sequences.rs
1use inputbot::{KeySequence, KeybdKey::*};
2
3/// This example demonstrates sending sequences of key presses / characters via a KeySequence.
4/// This can be used, for example, to create a macro which types a specific string.
5
6fn main() {
7 // If you are on Linux, you may wish to call this function first to avoid a startup delay when
8 // the fake device is created. Otherwise, your first input event - if it is a key sequence - may
9 // have missing characters.
10 // inputbot::init_device();
11
12 // Bind our Backquote key (`, ~) to a function that types out the string "Hello, world!".
13 // You must remember to call the `.send()` method on the KeySequence after creating it.
14 // You could explicitly define the KeySequence ahead of time and send it later like so:
15 // let seq: KeySequence = KeySequence("Hello, world!");
16 // seq.send();
17 BackquoteKey.bind(|| {
18 KeySequence("Hello, world!").send();
19 });
20
21 // Call this to start listening for bound inputs.
22 inputbot::handle_input_events();
23}