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
impl Mouse
Sourcepub fn new() -> Mouse
pub fn new() -> Mouse
This method creates a new mouse instance, must always be run before anything else
Sourcepub fn move_to(&self, x: i32, y: i32) -> Result<(), Box<dyn Error>>
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");
}
Sourcepub fn press<'a>(&self, button: &'a Keys) -> Result<(), Box<dyn Error + 'a>>
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
}Sourcepub fn release<'a>(&self, button: &'a Keys) -> Result<(), Box<dyn Error + 'a>>
pub fn release<'a>(&self, button: &'a Keys) -> Result<(), Box<dyn Error + 'a>>
This will release the button as noted above
Sourcepub fn get_position(&self) -> Result<Point, Box<dyn Error>>
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)
}Sourcepub fn wheel(&self, delta: i32) -> Result<(), Box<dyn Error>>
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);
}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 UnsafeUnpin for Mouse
impl UnwindSafe for Mouse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more