use rand::{rng, RngExt};
use windows::Win32::UI::WindowsAndMessaging::{
GetSystemMetrics, SetCursorPos, SM_CXSCREEN, SM_CYSCREEN,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Resolution {
pub width: i32,
pub height: i32,
}
pub fn get_resolution() -> Resolution {
let width = unsafe { GetSystemMetrics(SM_CXSCREEN) };
let height = unsafe { GetSystemMetrics(SM_CYSCREEN) };
Resolution {
width: width.max(1),
height: height.max(1),
}
}
pub fn teleport_mouse(x: i32, y: i32) -> bool {
unsafe { SetCursorPos(x, y).is_ok() }
}
pub fn teleport_random() -> (i32, i32) {
let res = get_resolution();
let mut rng = rng();
let x = rng.random_range(0..res.width);
let y = rng.random_range(0..res.height);
teleport_mouse(x, y);
(x, y)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn resolution_is_positive() {
let res = get_resolution();
assert!(res.width > 0);
assert!(res.height > 0);
}
}