Trait enigo::MouseControllable [] [src]

pub trait MouseControllable {
    fn mouse_move_to(&mut self, x: i32, y: i32);
    fn mouse_move_relative(&mut self, x: i32, y: i32);
    fn mouse_down(&mut self, button: u32);
    fn mouse_up(&mut self, button: u32);
    fn mouse_click(&mut self, button: u32);
    fn mouse_scroll_x(&mut self, length: i32);
    fn mouse_scroll_y(&mut self, length: i32);
}

Representing an interface and a set of mouse functions every operating system implementation should implement.

Required Methods

Lets the mouse cursor move to the specified x and y coordinates.

The topleft corner of your monitor screen is x=0 y=0. Move the cursor down the screen by increasing the y and to the right by increasing x coordinate.

Example

use enigo::*;
let mut enigo = Enigo::new();
enigo.mouse_move_to(500, 200);

Lets the mouse cursor move the specified amount in the x and y direction.

The amount specified in the x and y parameters are added to the current location of the mouse cursor. A positive x values lets the mouse cursor move an amount of x pixels to the right. A negative value for x lets the mouse cursor go to the right. A positive value of y lets the mouse cursor go down, a negative one lets the mouse cursor go up.

Example

use enigo::*;
let mut enigo = Enigo::new();
enigo.mouse_move_relative(100, 100);

Push down one of the mouse buttons

Push down the mouse button specified by the parameter button and holds it until it is released by mouse_up. Calls to mouse_move_to or mouse_move_relative will work like expected and will e.g. drag widgets or highlight text.

buttons are currently mapped like 1=left, 2=right, 3=middle in the linux implementation. On macOS and Windows only leftclicks are generated regardless of the parameter button – this will change in future version of course.

Example

use enigo::*;
let mut enigo = Enigo::new();
enigo.mouse_down(1);

Lift up a pushed down mouse button

Lift up a previously pushed down button (by invoking mouse_down). If the button was not pushed down or consecutive calls without invoking mouse_down will emit lift up events. It depends on the operating system whats actually happening – my guess is it will just get ignored.

buttons are currently mapped like 1=left, 2=right, 3=middle in the linux implementation. On macOS and Windows only leftclicks are generated regardless of the parameter button – this will change in future version of course.

Example

use enigo::*;
let mut enigo = Enigo::new();
enigo.mouse_up(1);

Click a mouse button

it's esentially just a consecutive invokation of mouse_down followed by a mouse_up. Just for convenience.

buttons are currently mapped like 1=left, 2=right, 3=middle in the linux implementation. On macOS and Windows only leftclicks are generated regardless of the parameter button – this will change in future version of course.

Example

use enigo::*;
let mut enigo = Enigo::new();
enigo.mouse_click(1);

Scroll the mouse (wheel) left or right

Positive numbers for length lets the mouse wheel scroll to the right and negative ones to the left. The value that is specified translates to lines defined by the operating system and is essentially one 15° (click)rotation on the mouse wheel. How many lines it moves depends on the current setting in the operating system.

Example

use enigo::*;
let mut enigo = Enigo::new();
enigo.mouse_scroll_x(2);

Scroll the mouse (wheel) up or down

Positive numbers for length lets the mouse wheel scroll down and negative ones up. The value that is specified translates to lines defined by the operating system and is essentially one 15° (click)rotation on the mouse wheel. How many lines it moves depends on the current setting in the operating system.

Example

use enigo::*;
let mut enigo = Enigo::new();
enigo.mouse_scroll_y(2);

Implementors