#[cfg(target_os = "windows")]
fn main() {
use std::time::Instant;
use windows::Win32::Foundation::POINT;
use windows::Win32::UI::WindowsAndMessaging::{GetCursorPos, SetCursorPos};
unsafe {
let t1 = Instant::now();
let mut original_pos = POINT { x: 0, y: 0 };
let result = GetCursorPos(&mut original_pos);
let get_cursor_time = t1.elapsed();
println!("GetCursorPos result: {:?}", result);
println!(
"Original cursor position: ({}, {})",
original_pos.x, original_pos.y
);
println!("GetCursorPos took: {:?}", get_cursor_time);
println!("\nMoving cursor to (500, 500)...");
let t2 = Instant::now();
let move_result = SetCursorPos(500, 500);
let set_cursor_time = t2.elapsed();
println!("SetCursorPos(500,500) result: {:?}", move_result);
println!("SetCursorPos took: {:?}", set_cursor_time);
std::thread::sleep(std::time::Duration::from_millis(100));
let mut new_pos = POINT { x: 0, y: 0 };
let _ = GetCursorPos(&mut new_pos);
println!("Current cursor position: ({}, {})", new_pos.x, new_pos.y);
println!("\nRestoring cursor to original position...");
let t3 = Instant::now();
let restore_result = SetCursorPos(original_pos.x, original_pos.y);
let restore_time = t3.elapsed();
println!("SetCursorPos restore result: {:?}", restore_result);
println!("SetCursorPos restore took: {:?}", restore_time);
std::thread::sleep(std::time::Duration::from_millis(100));
let mut final_pos = POINT { x: 0, y: 0 };
let _ = GetCursorPos(&mut final_pos);
println!("Final cursor position: ({}, {})", final_pos.x, final_pos.y);
println!("\n=== TIMING SUMMARY ===");
println!("GetCursorPos: {:?}", get_cursor_time);
println!("SetCursorPos: {:?}", set_cursor_time);
println!("Restore: {:?}", restore_time);
println!(
"Total overhead for save+restore: {:?}",
get_cursor_time + restore_time
);
if final_pos.x == original_pos.x && final_pos.y == original_pos.y {
println!("\nCursor restore WORKS!");
} else {
println!("\nCursor restore FAILED - position mismatch");
}
}
}
#[cfg(not(target_os = "windows"))]
fn main() {
println!("This test only runs on Windows");
}