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)
21
22
23
24
25
26
27
28
29
fn main() {
    let device = VirtualDevice::default().unwrap();

    let sender = device.sender.clone();

    device.flush_channel_every_interval();

    write_events_in_thread(sender).join().unwrap();
}
More examples
Hide additional examples
examples/keyboard.rs (line 7)
6
7
8
9
10
11
12
13
14
15
fn main() {
    let mut device = VirtualDevice::default().unwrap();

    thread::sleep(Duration::from_secs(2));

    // type hello
    for key in [KEY_H, KEY_E, KEY_L, KEY_L, KEY_O] {
        device.click(key).unwrap();
    }
}
examples/mouse.rs (line 7)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fn main() {
    let mut device = VirtualDevice::default().unwrap();

    for _ in 1..5 {
        thread::sleep(Duration::from_secs(1));

        // scroll vertically by 100
        device.scroll_y(100).unwrap();
        // move cursor vertically from the current position by 50
        device.move_mouse(50, 50).unwrap();
        //click the left mouse button
        device.click(BTN_LEFT).unwrap();
    }
}
source

pub fn new(writing_interval: Duration, channel_size: usize) -> Result<Self>

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)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fn write_events_in_thread(sender: ChannelSender) -> JoinHandle<()> {
    thread::spawn(move || {
        for _ in 1..5 {
            thread::sleep(Duration::from_secs(1));

            // scroll vertically by 100
            VirtualDevice::send_scroll_y(100, &sender.clone()).unwrap();
            // move cursor vertically from the current position by 50
            VirtualDevice::send_mouse_move(50, 50, &sender.clone()).unwrap();
            //click the left mouse button
            VirtualDevice::send_click(BTN_LEFT, &sender.clone()).unwrap();
        };
    })
}
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)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fn write_events_in_thread(sender: ChannelSender) -> JoinHandle<()> {
    thread::spawn(move || {
        for _ in 1..5 {
            thread::sleep(Duration::from_secs(1));

            // scroll vertically by 100
            VirtualDevice::send_scroll_y(100, &sender.clone()).unwrap();
            // move cursor vertically from the current position by 50
            VirtualDevice::send_mouse_move(50, 50, &sender.clone()).unwrap();
            //click the left mouse button
            VirtualDevice::send_click(BTN_LEFT, &sender.clone()).unwrap();
        };
    })
}
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)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fn write_events_in_thread(sender: ChannelSender) -> JoinHandle<()> {
    thread::spawn(move || {
        for _ in 1..5 {
            thread::sleep(Duration::from_secs(1));

            // scroll vertically by 100
            VirtualDevice::send_scroll_y(100, &sender.clone()).unwrap();
            // move cursor vertically from the current position by 50
            VirtualDevice::send_mouse_move(50, 50, &sender.clone()).unwrap();
            //click the left mouse button
            VirtualDevice::send_click(BTN_LEFT, &sender.clone()).unwrap();
        };
    })
}
source

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

Examples found in repository?
examples/channels.rs (line 26)
21
22
23
24
25
26
27
28
29
fn main() {
    let device = VirtualDevice::default().unwrap();

    let sender = device.sender.clone();

    device.flush_channel_every_interval();

    write_events_in_thread(sender).join().unwrap();
}
source

pub fn synchronize(&mut self) -> EmptyResult

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 15)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fn main() {
    let mut device = VirtualDevice::default().unwrap();

    for _ in 1..5 {
        thread::sleep(Duration::from_secs(1));

        // scroll vertically by 100
        device.scroll_y(100).unwrap();
        // move cursor vertically from the current position by 50
        device.move_mouse(50, 50).unwrap();
        //click the left mouse button
        device.click(BTN_LEFT).unwrap();
    }
}
source

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

source

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

Examples found in repository?
examples/mouse.rs (line 13)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fn main() {
    let mut device = VirtualDevice::default().unwrap();

    for _ in 1..5 {
        thread::sleep(Duration::from_secs(1));

        // scroll vertically by 100
        device.scroll_y(100).unwrap();
        // move cursor vertically from the current position by 50
        device.move_mouse(50, 50).unwrap();
        //click the left mouse button
        device.click(BTN_LEFT).unwrap();
    }
}
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)
6
7
8
9
10
11
12
13
14
15
fn main() {
    let mut device = VirtualDevice::default().unwrap();

    thread::sleep(Duration::from_secs(2));

    // type hello
    for key in [KEY_H, KEY_E, KEY_L, KEY_L, KEY_O] {
        device.click(key).unwrap();
    }
}
More examples
Hide additional examples
examples/mouse.rs (line 17)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fn main() {
    let mut device = VirtualDevice::default().unwrap();

    for _ in 1..5 {
        thread::sleep(Duration::from_secs(1));

        // scroll vertically by 100
        device.scroll_y(100).unwrap();
        // move cursor vertically from the current position by 50
        device.move_mouse(50, 50).unwrap();
        //click the left mouse button
        device.click(BTN_LEFT).unwrap();
    }
}

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.