add: basic F key mash macro sample

v0.1.1
rrr-marble 5 years ago
parent e1b8988843
commit 2d00486f6b

@ -36,7 +36,7 @@ fn run(input_device: &'static evdev::Device, pedals: impl Iterator<Item = Pedal>
} }
for recieved in rx { for recieved in rx {
println!("{}", recieved); println!("{:?}", recieved);
} }
for handle in handles { for handle in handles {
@ -81,5 +81,5 @@ fn create_device() -> Result<evdev::uinput::VirtualDevice, Box<dyn std::error::E
pub struct Pedal { pub struct Pedal {
key: evdev::Key, key: evdev::Key,
action: Box<dyn Fn(&std::sync::mpsc::Sender<String>) -> () + Send + 'static>, action: Box<dyn Fn(&std::sync::mpsc::Sender<evdev::InputEvent>) -> () + Send + 'static>,
} }

@ -1,19 +1,27 @@
pub use crate::Pedal; pub use crate::Pedal;
use evdev::Key; use evdev::{EventType, InputEvent, Key};
pub fn pedals() -> Vec<Pedal> { pub fn pedals() -> Vec<Pedal> {
vec![ vec![
Pedal { Pedal {
key: Key::BTN_SIDE, key: Key::BTN_SIDE,
action: Box::new(|tx| tx.send(String::from("BTN_SIDE")).unwrap()), action: Box::new(|tx| ()),
}, },
Pedal { Pedal {
key: Key::BTN_EXTRA, key: Key::BTN_EXTRA,
action: Box::new(|tx| tx.send(String::from("BTN_EXTRA")).unwrap()), action: Box::new(|tx| {
let code = Key::KEY_F.code();
let down_event = InputEvent::new(EventType::KEY, code, 1);
let up_event = InputEvent::new(EventType::KEY, code, 0);
tx.send(down_event).unwrap();
std::thread::sleep(std::time::Duration::from_millis(24));
tx.send(up_event).unwrap();
std::thread::sleep(std::time::Duration::from_millis(33));
}),
}, },
Pedal { Pedal {
key: Key::BTN_RIGHT, key: Key::BTN_RIGHT,
action: Box::new(|tx| tx.send(String::from("BTN_RIGHT")).unwrap()), action: Box::new(|tx| ()),
}, },
] ]
} }

Loading…
Cancel
Save