Crates.io | mouce |
lib.rs | mouce |
version | 0.2.50 |
source | src |
created_at | 2022-04-12 14:42:03.567782 |
updated_at | 2024-12-09 12:36:38.659673 |
description | A library that aims to help simulating and listening mouse actions across different platforms. |
homepage | https://github.com/emrebicer/mouce |
repository | https://github.com/emrebicer/mouce |
max_upload_size | |
id | 566471 |
size | 86,912 |
Mouce is a library written in Rust that aims to help simulating and listening mouse actions across different platforms.
--no-default-features
argument with cargoCargo.toml
[dependencies]
mouce = { version = "x.y.z", default-features = false }
get_position
function is not implemented as uinput does not provide such a feature/// Move the mouse to the given `x`, `y` coordinates
fn move_to(&self, x: usize, y: usize) -> Result<(), Error>;
/// Move the mouse relative to the current position
fn move_relative(&self, x_offset: i32, y_offset: i32) -> Result<(), Error>;
/// Get the current position of the mouse
fn get_position(&self) -> Result<(i32, i32), Error>;
/// Press down the given mouse button
fn press_button(&self, button: &MouseButton) -> Result<(), Error>;
/// Release the given mouse button
fn release_button(&self, button: &MouseButton) -> Result<(), Error>;
/// Click the given mouse button
fn click_button(&self, button: &MouseButton) -> Result<(), Error>;
/// Scroll the mouse wheel towards to the given direction
fn scroll_wheel(&self, direction: &ScrollDirection) -> Result<(), Error>;
/// Attach a callback function to mouse events
fn hook(&mut self, callback: Box<dyn Fn(&MouseEvent) + Send>) -> Result<CallbackId, Error>;
/// Remove the callback function with the given `CallbackId`
fn unhook(&mut self, callback_id: CallbackId) -> Result<(), Error>;
/// Remove all callback functions
fn unhook_all(&mut self) -> Result<(), Error>;
This example program moves the mouse from left to right;
use std::thread;
use std::time::Duration;
use mouce::{Mouse, MouseActions};
fn main() {
let mouse_manager = Mouse::new();
let mut x = 0;
while x < 1920 {
let _ = mouse_manager.move_to(x, 540);
x += 1;
thread::sleep(Duration::from_millis(2));
}
}
To see more examples, you can look at the documentation by running;
cargo doc --open
mouce comes with an example CLI program that uses mouce library functions. You can install the binary with;
cargo install mouce --features="cli"
and see mouce --help
for further details.