Struct Mouse

Source
pub struct Mouse(/* private fields */);
Expand description

Struct for the mouse

This struct represents a mouse and doesn’t hold any values

Implementations§

Source§

impl Mouse

Source

pub fn new() -> Mouse

This method creates a new mouse instance, must always be run before anything else

Source

pub fn move_to(&self, x: i32, y: i32) -> Result<(), Box<dyn Error>>

This method moves the mouse around

§Examples
use mouse_rs::{types::keys::*, Mouse};

fn move_mouse() {
    let mouse = Mouse::new();
    mouse.move_to(500, 500).expect("Unable to move mouse");
}
Source

pub fn press<'a>(&self, button: &'a Keys) -> Result<(), Box<dyn Error + 'a>>

This method presses the given button in

NOTE: This doesn’t release the button so it will keep pressing

§Examples
use mouse_rs::{types::keys::Keys, Mouse};

fn press_button() {
    let mouse = Mouse::new();
    mouse.press(&Keys::LEFT).expect("Unable to press button"); // This will keep pressing
}

fn press_and_release_button() {
    let mouse = Mouse::new();
    mouse.press(&Keys::RIGHT).expect("Unable to press button");
    mouse.release(&Keys::RIGHT).expect("Unable to release button"); // This will press the right mouse quickly
}
Source

pub fn release<'a>(&self, button: &'a Keys) -> Result<(), Box<dyn Error + 'a>>

This will release the button as noted above

Source

pub fn get_position(&self) -> Result<Point, Box<dyn Error>>

This gets the current mouse position

§Example
use mouse_rs::Mouse;

fn get_post() {
    let mouse = Mouse::new();
    let pos = mouse.get_position().unwrap();
    println!("X = {}, Y = {}", pos.x, pos.y)
}
Source

pub fn wheel(&self, delta: i32) -> Result<(), Box<dyn Error>>

This will scroll the mouse,

For scrolling down use negative values, for scrolling up use positive values

§Examples
use mouse_rs::{types::keys::*, Mouse};

fn scroll_up() {
    let mouse = Mouse::new();
    mouse.wheel(1);
}

fn scroll_down() {
    let mouse = Mouse::new();
    mouse.wheel(-1);
}
Source

pub fn scroll(&self, delta: i32) -> Result<(), Box<dyn Error>>

This is the exact same as wheel

Source

pub fn click<'a>(&self, button: &'a Keys) -> Result<(), Box<dyn Error + 'a>>

Auto Trait Implementations§

§

impl Freeze for Mouse

§

impl RefUnwindSafe for Mouse

§

impl Send for Mouse

§

impl Sync for Mouse

§

impl Unpin for Mouse

§

impl UnwindSafe for Mouse

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.