Trait enigo_copy::MouseControllable
source · pub trait MouseControllable {
// Required methods
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: MouseButton);
fn mouse_up(&mut self, button: MouseButton);
fn mouse_click(&mut self, button: MouseButton);
fn mouse_scroll_x(&mut self, length: i32);
fn mouse_scroll_y(&mut self, length: i32);
fn main_display_size(&self) -> (i32, i32);
fn mouse_location(&self) -> (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§
sourcefn mouse_move_to(&mut self, x: i32, y: i32)
fn mouse_move_to(&mut self, x: i32, y: i32)
Move the mouse cursor 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);
sourcefn mouse_move_relative(&mut self, x: i32, y: i32)
fn mouse_move_relative(&mut self, x: i32, y: i32)
Move the mouse cursor the specified amount in the x and y
direction. 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.
Example
use enigo::*;
let mut enigo = Enigo::new();
enigo.mouse_move_relative(100, 100);
sourcefn mouse_down(&mut self, button: MouseButton)
fn mouse_down(&mut self, button: MouseButton)
Push down the mouse button specified by the parameter
button
of type MouseButton
and hold it until it is released by
MouseControllable::mouse_up
.
Calls to MouseControllable::mouse_move_to
or
MouseControllable::mouse_move_relative
will
work like expected and will e.g. drag widgets or highlight text.
Example
use enigo::*;
let mut enigo = Enigo::new();
enigo.mouse_down(MouseButton::Left);
sourcefn mouse_up(&mut self, button: MouseButton)
fn mouse_up(&mut self, button: MouseButton)
Release a pushed down mouse button
Lift up a previously pushed down button (by invoking
MouseControllable::mouse_down
).
If the button was not pushed down or consecutive calls without
invoking MouseControllable::mouse_down
will emit lift up
events. It depends on the operating system whats actually happening
– my guess is it will just get ignored.
Example
use enigo::*;
let mut enigo = Enigo::new();
enigo.mouse_down(MouseButton::Right);
enigo.mouse_up(MouseButton::Right);
sourcefn mouse_click(&mut self, button: MouseButton)
fn mouse_click(&mut self, button: MouseButton)
Click a mouse button
It is essentially just a consecutive invocation of
MouseControllable::mouse_down
followed by a MouseControllable::mouse_up
. Just for
convenience.
Example
use enigo::*;
let mut enigo = Enigo::new();
enigo.mouse_click(MouseButton::Right);
sourcefn mouse_scroll_x(&mut self, length: i32)
fn mouse_scroll_x(&mut self, length: i32)
Scroll the mouse (wheel) left or right
Positive numbers for length
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);
sourcefn mouse_scroll_y(&mut self, length: i32)
fn mouse_scroll_y(&mut self, length: i32)
Scroll the mouse (wheel) up or down
Positive numbers for length
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);
sourcefn main_display_size(&self) -> (i32, i32)
fn main_display_size(&self) -> (i32, i32)
Get the (width, height) of the main display in screen coordinates (pixels). This currently only works on the main display
Example
use enigo::*;
let mut enigo = Enigo::new();
let (width, height) = enigo.main_display_size();
sourcefn mouse_location(&self) -> (i32, i32)
fn mouse_location(&self) -> (i32, i32)
Get the location of the mouse in screen coordinates (pixels).
Example
use enigo::*;
let mut enigo = Enigo::new();
let (x, y) = enigo.mouse_location();