use winapi::shared::windef::POINT;
use winapi::um::winuser::{GetCursorPos, SetCursorPos};
pub fn location() -> Option<Location> {
unsafe {
let mut point = POINT { x: 0, y: 0 };
if GetCursorPos(&mut point) != 0 {
Some((point.x as _, point.y as _))
} else {
None
}
}
}
#[inline]
pub fn set_location((x, y): (usize, usize)) -> bool {
unsafe { SetCursorPos(x as _, y as _) != 0 }
}
pub type Location = (usize, usize);
#[cfg(test)]
mod tests {
#[test]
fn location() {
let orig = super::location().expect("Cannot get mouse location");
let other = (40, 10);
assert!(super::set_location(other));
assert_eq!(super::location(), Some(other));
assert!(super::set_location(orig));
assert_eq!(super::location(), Some(orig));
}
}