-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathserde.rs
More file actions
36 lines (31 loc) · 1.16 KB
/
serde.rs
File metadata and controls
36 lines (31 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use inputbot::{KeySequence, KeybdKey};
use serde::Deserialize;
use toml;
/// This example demonstrates sending sequences of key presses / characters via a KeySequence.
/// This can be used, for example, to create a macro which types a specific string.
fn main() -> Result<(), Box<dyn std::error::Error>> {
// If you are on Linux, you may wish to call this function first to avoid a startup delay when
// the fake device is created. Otherwise, your first input event - if it is a key sequence - may
// have missing characters.
// inputbot::init_device();
// With the serde feature, KeybdKey and MouseButton are Deserialize, so structs
// that include these types can derive Deserialize.
#[derive(Deserialize)]
struct Config {
hello: KeybdKey,
world: KeybdKey,
}
let config: Config = toml::from_str(
r#"
hello = "numpad1"
world = "numpad2"
"#,
)?;
config.hello.block_bind(|| {
KeySequence("Hello,").send();
});
config.world.block_bind(|| KeySequence(" World!").send());
// Call this to start listening for bound inputs.
inputbot::handle_input_events(false);
Ok(())
}