Trait enigo::Mouse

source ·
pub trait Mouse {
    // Required methods
    fn button(
        &mut self,
        button: Button,
        direction: Direction
    ) -> InputResult<()>;
    fn move_mouse(
        &mut self,
        x: i32,
        y: i32,
        coordinate: Coordinate
    ) -> InputResult<()>;
    fn scroll(&mut self, length: i32, axis: Axis) -> InputResult<()>;
    fn main_display(&self) -> InputResult<(i32, i32)>;
    fn location(&self) -> InputResult<(i32, i32)>;
}
Expand description

Contains functions to control the mouse and to get the size of the display. Enigo uses a cartesian coordinate system for specifying coordinates. The origin in this system is located in the top-left corner of the current screen, with positive values extending along the axes down and to the right of the origin point and it is measured in pixels. The same coordinate system is used on all operating systems.

Required Methods§

source

fn button(&mut self, button: Button, direction: Direction) -> InputResult<()>

Sends an individual mouse button event. You can use this for example to simulate a click of the left mouse key. Some of the buttons are specific to a platform.

§Errors

Have a look at the documentation of InputError to see under which conditions an error will be returned.

source

fn move_mouse( &mut self, x: i32, y: i32, coordinate: Coordinate ) -> InputResult<()>

Move the mouse cursor to the specified x and y coordinates.

You can specify absolute coordinates or relative from the current position.

If you use absolute coordinates, the top left 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.

If you use relative coordinates, a positive x value moves the mouse cursor x pixels to the right. A negative value for x moves the mouse cursor to the left. A positive value of y moves the mouse cursor down, a negative one moves the mouse cursor up.

§Errors

Have a look at the documentation of InputError to see under which conditions an error will be returned.

source

fn scroll(&mut self, length: i32, axis: Axis) -> InputResult<()>

Send a mouse scroll event

§Arguments
  • axis - The axis to scroll on
  • length - Number of 15° (click) rotations of the mouse wheel to scroll. How many lines will be scrolled depends on the current setting of the operating system.

With Axis::Vertical, a positive length will result in scrolling down and negative ones up. With Axis::Horizontal, a positive length will result in scrolling to the right and negative ones to the left

§Errors

Have a look at the documentation of InputError to see under which conditions an error will be returned.

source

fn main_display(&self) -> InputResult<(i32, i32)>

Get the (width, height) of the main display in pixels. This currently only works on the main display

§Errors

Have a look at the documentation of InputError to see under which conditions an error will be returned.

source

fn location(&self) -> InputResult<(i32, i32)>

Get the location of the mouse in pixels

§Errors

Have a look at the documentation of InputError to see under which conditions an error will be returned.

Implementors§