mouse.rs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. use enigo::{Enigo, MouseButton, MouseControllable};
  2. #[cfg(windows)]
  3. use winapi::um::winuser::WHEEL_DELTA;
  4. use std::thread;
  5. use std::time::Duration;
  6. fn main() {
  7. let wait_time = Duration::from_secs(2);
  8. let mut enigo = Enigo::new();
  9. thread::sleep(wait_time);
  10. enigo.mouse_move_to(500, 200);
  11. thread::sleep(wait_time);
  12. enigo.mouse_down(MouseButton::Left).ok();
  13. thread::sleep(wait_time);
  14. enigo.mouse_move_relative(100, 100);
  15. thread::sleep(wait_time);
  16. enigo.mouse_up(MouseButton::Left);
  17. thread::sleep(wait_time);
  18. enigo.mouse_click(MouseButton::Left);
  19. thread::sleep(wait_time);
  20. #[cfg(not(target_os = "macos"))]
  21. {
  22. #[cfg(windows)]
  23. enigo.mouse_scroll_x(2 * WHEEL_DELTA as i32);
  24. #[cfg(not(windows))]
  25. enigo.mouse_scroll_x(2);
  26. thread::sleep(wait_time);
  27. #[cfg(windows)]
  28. enigo.mouse_scroll_x(-2 * WHEEL_DELTA as i32);
  29. #[cfg(not(windows))]
  30. enigo.mouse_scroll_x(-2);
  31. thread::sleep(wait_time);
  32. #[cfg(windows)]
  33. enigo.mouse_scroll_y(2 * WHEEL_DELTA as i32);
  34. #[cfg(not(windows))]
  35. enigo.mouse_scroll_y(2);
  36. thread::sleep(wait_time);
  37. #[cfg(windows)]
  38. enigo.mouse_scroll_y(-2 * WHEEL_DELTA as i32);
  39. #[cfg(not(windows))]
  40. enigo.mouse_scroll_y(-2);
  41. thread::sleep(wait_time);
  42. }
  43. }