use crate::error::WindowsError;
#[cfg(not(feature = "minimal"))]
use crate::input::{send_inputs, Input, MouseMotion, WheelDirection};
use winapi::shared::windef;
use winapi::um::winuser;
pub struct Mouse;
impl Mouse {
pub fn position() -> Result<(i32, i32), WindowsError> {
unsafe {
let mut point: windef::POINT = std::mem::zeroed();
if winuser::GetCursorPos(&mut point) != 0 {
Ok((point.x, point.y))
} else {
Err(WindowsError::from_last_error())
}
}
}
pub fn set_position(x: i32, y: i32) -> Result<(), WindowsError> {
unsafe {
if winuser::SetCursorPos(x, y) == 0 {
Err(WindowsError::from_last_error())
} else {
Ok(())
}
}
}
#[cfg(not(feature = "minimal"))]
pub fn scroll(amount: f32) {
let input = Input::from_wheel(amount, WheelDirection::Vertical);
send_inputs(&[input]);
}
#[cfg(not(feature = "minimal"))]
pub fn scrollh(amount: f32) {
let input = Input::from_wheel(amount, WheelDirection::Horizontal);
send_inputs(&[input]);
}
#[cfg(not(feature = "minimal"))]
pub fn move_relative(dx: i32, dy: i32) {
let motion = MouseMotion::Relative { dx, dy };
let input = Input::from_motion(motion);
send_inputs(&[input]);
}
#[cfg(not(feature = "minimal"))]
pub fn move_absolute(x: f32, y: f32) {
let motion = MouseMotion::Absolute {
x,
y,
virtual_desk: false,
};
let input = Input::from_motion(motion);
send_inputs(&[input]);
}
}