Struct VirtualDevice

Source
pub struct VirtualDevice {
    pub sender: ChannelSender,
    /* private fields */
}

Fields§

§sender: ChannelSender

Implementations§

Source§

impl VirtualDevice

Source

pub fn default() -> Result<Self>

Examples found in repository?
examples/channels.rs (line 22)
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}
More examples
Hide additional examples
examples/keyboard.rs (line 7)
6fn main() {
7    let mut device = VirtualDevice::default().unwrap();
8
9    thread::sleep(Duration::from_secs(2));
10
11    // type hello
12    for key in [KEY_H, KEY_E, KEY_L, KEY_L, KEY_O] {
13        device.click(key).unwrap();
14    }
15}
examples/mouse.rs (line 7)
6fn main() {
7    let mut device = VirtualDevice::default().unwrap();
8
9    for _ in 1..3 {
10        thread::sleep(Duration::from_secs(1));
11
12        // gradually scroll down by 100
13        device.smooth_scroll(0, -100).unwrap();
14        // gradually move cursor 250 pixels up and 250 pixels to the right from the current position
15        device.smooth_move_mouse(250, 250).unwrap();
16        //click the left mouse button
17        device.click(BTN_RIGHT).unwrap();
18    }
19
20    for _ in 1..2 {
21        thread::sleep(Duration::from_secs(1));
22
23        // scroll down by 100
24        device.scroll_y(-100).unwrap();
25        // instantly move cursor 250 pixels up and 250 pixels to the right from the current position
26        device.move_mouse(250, 250).unwrap();
27        //click the left mouse button
28        device.click(BTN_RIGHT).unwrap();
29    }
30}
Source

pub fn send_to_channel( kind: u16, code: u16, value: i32, sender: &ChannelSender, ) -> EmptyResult

Source

pub fn send_press(button: Button, sender: &ChannelSender) -> EmptyResult

Source

pub fn send_release(button: Button, sender: &ChannelSender) -> EmptyResult

Source

pub fn send_click(button: Button, sender: &ChannelSender) -> EmptyResult

Examples found in repository?
examples/channels.rs (line 16)
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}
Source

pub fn send_mouse_move_x(x: Coord, sender: &ChannelSender) -> EmptyResult

Source

pub fn send_mouse_move_y(y: Coord, sender: &ChannelSender) -> EmptyResult

Source

pub fn send_mouse_move( x: Coord, y: Coord, sender: &ChannelSender, ) -> EmptyResult

Examples found in repository?
examples/channels.rs (line 14)
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}
Source

pub fn send_scroll_x(value: Coord, sender: &ChannelSender) -> EmptyResult

Source

pub fn send_scroll_y(value: Coord, sender: &ChannelSender) -> EmptyResult

Examples found in repository?
examples/channels.rs (line 12)
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}
Source

pub fn flush_channel_every_interval(self) -> JoinHandle<()>

Examples found in repository?
examples/channels.rs (line 26)
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}
Source

pub fn write_batch(&mut self, batch: &[EventParams]) -> EmptyResult

Source

pub fn synchronize(&mut self) -> EmptyResult

Source

pub fn move_mouse_raw_x(&mut self, x: Coord) -> EmptyResult

Source

pub fn move_mouse_raw_y(&mut self, y: Coord) -> EmptyResult

Source

pub fn move_mouse_raw(&mut self, x: Coord, y: Coord) -> EmptyResult

Source

pub fn buffered_move_mouse_x(&mut self, x: Coord) -> Vec<EventParams>

Source

pub fn buffered_move_mouse_y(&mut self, y: Coord) -> Vec<EventParams>

Source

pub fn buffered_move_mouse(&mut self, x: Coord, y: Coord) -> Vec<EventParams>

Source

pub fn gradual_move_mouse_raw(&mut self, x: Coord, y: Coord) -> Result<()>

Source

pub fn smooth_move_mouse(&mut self, x: Coord, y: Coord) -> Result<()>

Examples found in repository?
examples/mouse.rs (line 15)
6fn main() {
7    let mut device = VirtualDevice::default().unwrap();
8
9    for _ in 1..3 {
10        thread::sleep(Duration::from_secs(1));
11
12        // gradually scroll down by 100
13        device.smooth_scroll(0, -100).unwrap();
14        // gradually move cursor 250 pixels up and 250 pixels to the right from the current position
15        device.smooth_move_mouse(250, 250).unwrap();
16        //click the left mouse button
17        device.click(BTN_RIGHT).unwrap();
18    }
19
20    for _ in 1..2 {
21        thread::sleep(Duration::from_secs(1));
22
23        // scroll down by 100
24        device.scroll_y(-100).unwrap();
25        // instantly move cursor 250 pixels up and 250 pixels to the right from the current position
26        device.move_mouse(250, 250).unwrap();
27        //click the left mouse button
28        device.click(BTN_RIGHT).unwrap();
29    }
30}
Source

pub fn buffered_gradual_move_mouse( &mut self, x: Coord, y: Coord, ) -> Vec<EventParams>

Source

pub fn move_mouse_x(&mut self, x: Coord) -> EmptyResult

Source

pub fn move_mouse_y(&mut self, y: Coord) -> EmptyResult

Source

pub fn move_mouse(&mut self, x: Coord, y: Coord) -> EmptyResult

Examples found in repository?
examples/mouse.rs (line 26)
6fn main() {
7    let mut device = VirtualDevice::default().unwrap();
8
9    for _ in 1..3 {
10        thread::sleep(Duration::from_secs(1));
11
12        // gradually scroll down by 100
13        device.smooth_scroll(0, -100).unwrap();
14        // gradually move cursor 250 pixels up and 250 pixels to the right from the current position
15        device.smooth_move_mouse(250, 250).unwrap();
16        //click the left mouse button
17        device.click(BTN_RIGHT).unwrap();
18    }
19
20    for _ in 1..2 {
21        thread::sleep(Duration::from_secs(1));
22
23        // scroll down by 100
24        device.scroll_y(-100).unwrap();
25        // instantly move cursor 250 pixels up and 250 pixels to the right from the current position
26        device.move_mouse(250, 250).unwrap();
27        //click the left mouse button
28        device.click(BTN_RIGHT).unwrap();
29    }
30}
Source

pub fn scroll_raw_x(&mut self, value: Coord) -> EmptyResult

Source

pub fn scroll_raw_y(&mut self, value: Coord) -> EmptyResult

Source

pub fn buffered_scroll_x(&mut self, value: Coord) -> Vec<EventParams>

Source

pub fn buffered_scroll_y(&mut self, value: Coord) -> Vec<EventParams>

Source

pub fn scroll_x(&mut self, value: Coord) -> EmptyResult

Source

pub fn gradual_scroll_raw(&mut self, x: Coord, y: Coord) -> Result<()>

Source

pub fn smooth_scroll(&mut self, x: Coord, y: Coord) -> Result<()>

Examples found in repository?
examples/mouse.rs (line 13)
6fn main() {
7    let mut device = VirtualDevice::default().unwrap();
8
9    for _ in 1..3 {
10        thread::sleep(Duration::from_secs(1));
11
12        // gradually scroll down by 100
13        device.smooth_scroll(0, -100).unwrap();
14        // gradually move cursor 250 pixels up and 250 pixels to the right from the current position
15        device.smooth_move_mouse(250, 250).unwrap();
16        //click the left mouse button
17        device.click(BTN_RIGHT).unwrap();
18    }
19
20    for _ in 1..2 {
21        thread::sleep(Duration::from_secs(1));
22
23        // scroll down by 100
24        device.scroll_y(-100).unwrap();
25        // instantly move cursor 250 pixels up and 250 pixels to the right from the current position
26        device.move_mouse(250, 250).unwrap();
27        //click the left mouse button
28        device.click(BTN_RIGHT).unwrap();
29    }
30}
Source

pub fn buffered_gradual_scroll( &mut self, x: Coord, y: Coord, ) -> Vec<EventParams>

Source

pub fn scroll_y(&mut self, value: Coord) -> EmptyResult

Examples found in repository?
examples/mouse.rs (line 24)
6fn main() {
7    let mut device = VirtualDevice::default().unwrap();
8
9    for _ in 1..3 {
10        thread::sleep(Duration::from_secs(1));
11
12        // gradually scroll down by 100
13        device.smooth_scroll(0, -100).unwrap();
14        // gradually move cursor 250 pixels up and 250 pixels to the right from the current position
15        device.smooth_move_mouse(250, 250).unwrap();
16        //click the left mouse button
17        device.click(BTN_RIGHT).unwrap();
18    }
19
20    for _ in 1..2 {
21        thread::sleep(Duration::from_secs(1));
22
23        // scroll down by 100
24        device.scroll_y(-100).unwrap();
25        // instantly move cursor 250 pixels up and 250 pixels to the right from the current position
26        device.move_mouse(250, 250).unwrap();
27        //click the left mouse button
28        device.click(BTN_RIGHT).unwrap();
29    }
30}
Source

pub fn buffered_press(&mut self, button: Button) -> Vec<EventParams>

Source

pub fn buffered_release(&mut self, button: Button) -> Vec<EventParams>

Source

pub fn press(&mut self, button: Button) -> EmptyResult

Source

pub fn release(&mut self, button: Button) -> EmptyResult

Source

pub fn click(&mut self, button: Button) -> EmptyResult

Examples found in repository?
examples/keyboard.rs (line 13)
6fn main() {
7    let mut device = VirtualDevice::default().unwrap();
8
9    thread::sleep(Duration::from_secs(2));
10
11    // type hello
12    for key in [KEY_H, KEY_E, KEY_L, KEY_L, KEY_O] {
13        device.click(key).unwrap();
14    }
15}
More examples
Hide additional examples
examples/mouse.rs (line 17)
6fn main() {
7    let mut device = VirtualDevice::default().unwrap();
8
9    for _ in 1..3 {
10        thread::sleep(Duration::from_secs(1));
11
12        // gradually scroll down by 100
13        device.smooth_scroll(0, -100).unwrap();
14        // gradually move cursor 250 pixels up and 250 pixels to the right from the current position
15        device.smooth_move_mouse(250, 250).unwrap();
16        //click the left mouse button
17        device.click(BTN_RIGHT).unwrap();
18    }
19
20    for _ in 1..2 {
21        thread::sleep(Duration::from_secs(1));
22
23        // scroll down by 100
24        device.scroll_y(-100).unwrap();
25        // instantly move cursor 250 pixels up and 250 pixels to the right from the current position
26        device.move_mouse(250, 250).unwrap();
27        //click the left mouse button
28        device.click(BTN_RIGHT).unwrap();
29    }
30}

Trait Implementations§

Source§

impl Drop for VirtualDevice

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.