pub struct Triggers { /* private fields */ }
Expand description
Data structure containing the triggers registered for
all the keyboards. Once triggers have been registered,
use the Triggers::listen
method to enable the
detection.
Implementations§
Source§impl Triggers
impl Triggers
Sourcepub fn insert(&mut self, triggers: KeyboardTriggers)
pub fn insert(&mut self, triggers: KeyboardTriggers)
Registers all the triggers for a specific keyboard, overriding previous definitions.
Examples found in repository?
examples/basic.rs (line 41)
5fn main() {
6 std::thread::spawn(|| {
7 // Security in case devices were grabbed unintentionally
8 // to avoid being locked out of the computer
9 std::thread::sleep(Duration::from_secs(120));
10 std::process::exit(1);
11 });
12
13 // Obtain the name of the keyboard
14 let mut keyboard_name = String::new();
15 print!("Please provide the name of your macro keyboard: ");
16 std::io::stdout().flush().expect("failed to flush stdout");
17 std::io::stdin()
18 .read_line(&mut keyboard_name)
19 .expect("failed to read keyboard name");
20
21 // Register the keyboard triggers
22 let mut keyboard_triggers = KeyboardTriggers::new(keyboard_name.trim());
23
24 keyboard_triggers.insert_with_release(
25 &[KeyMappingCode::ControlLeft, KeyMappingCode::KeyE],
26 || println!("Ran combination!"),
27 || println!("Released combination!"),
28 );
29
30 keyboard_triggers.insert_with_release(
31 &[KeyMappingCode::KeyR],
32 || println!("Trigger start!"),
33 || println!("Trigger stop!"),
34 );
35
36 keyboard_triggers.insert(&[KeyMappingCode::KeyE], || println!("Hello!"));
37
38 keyboard_triggers.insert(&[KeyMappingCode::Escape], || ListeningCmd::Stop);
39
40 let mut triggers = Triggers::default();
41 triggers.insert(keyboard_triggers);
42
43 // Start the event loop
44 triggers.listen();
45
46 println!("Listener gracefully stopped.");
47}
Sourcepub fn listen(self)
pub fn listen(self)
Blocks the thread to detect inputs for the configured keyboards and run the actions associated to key combinations.
Examples found in repository?
examples/basic.rs (line 44)
5fn main() {
6 std::thread::spawn(|| {
7 // Security in case devices were grabbed unintentionally
8 // to avoid being locked out of the computer
9 std::thread::sleep(Duration::from_secs(120));
10 std::process::exit(1);
11 });
12
13 // Obtain the name of the keyboard
14 let mut keyboard_name = String::new();
15 print!("Please provide the name of your macro keyboard: ");
16 std::io::stdout().flush().expect("failed to flush stdout");
17 std::io::stdin()
18 .read_line(&mut keyboard_name)
19 .expect("failed to read keyboard name");
20
21 // Register the keyboard triggers
22 let mut keyboard_triggers = KeyboardTriggers::new(keyboard_name.trim());
23
24 keyboard_triggers.insert_with_release(
25 &[KeyMappingCode::ControlLeft, KeyMappingCode::KeyE],
26 || println!("Ran combination!"),
27 || println!("Released combination!"),
28 );
29
30 keyboard_triggers.insert_with_release(
31 &[KeyMappingCode::KeyR],
32 || println!("Trigger start!"),
33 || println!("Trigger stop!"),
34 );
35
36 keyboard_triggers.insert(&[KeyMappingCode::KeyE], || println!("Hello!"));
37
38 keyboard_triggers.insert(&[KeyMappingCode::Escape], || ListeningCmd::Stop);
39
40 let mut triggers = Triggers::default();
41 triggers.insert(keyboard_triggers);
42
43 // Start the event loop
44 triggers.listen();
45
46 println!("Listener gracefully stopped.");
47}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Triggers
impl !RefUnwindSafe for Triggers
impl !Send for Triggers
impl !Sync for Triggers
impl Unpin for Triggers
impl !UnwindSafe for Triggers
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more