channels/
channels.rs

1use mouse_keyboard_input::*;
2use std::thread;
3use std::thread::JoinHandle;
4use std::time::Duration;
5
6fn write_events_in_thread(sender: ChannelSender) -> JoinHandle<()> {
7    thread::spawn(move || {
8        for _ in 1..5 {
9            thread::sleep(Duration::from_secs(1));
10
11            // scroll vertically by 100
12            VirtualDevice::send_scroll_y(100, &sender.clone()).unwrap();
13            // move cursor vertically from the current position by 50
14            VirtualDevice::send_mouse_move(50, 50, &sender.clone()).unwrap();
15            //click the left mouse button
16            VirtualDevice::send_click(BTN_LEFT, &sender.clone()).unwrap();
17        };
18    })
19}
20
21fn main() {
22    let device = VirtualDevice::default().unwrap();
23
24    let sender = device.sender.clone();
25
26    device.flush_channel_every_interval();
27
28    write_events_in_thread(sender).join().unwrap();
29}