2021-03-29 15:59:14 +08:00
|
|
|
use enigo::{Enigo, MouseButton, MouseControllable};
|
2023-06-07 21:17:13 +08:00
|
|
|
#[cfg(windows)]
|
2023-06-07 20:01:01 +08:00
|
|
|
use winapi::um::winuser::WHEEL_DELTA;
|
2021-03-29 15:59:14 +08:00
|
|
|
use std::thread;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let wait_time = Duration::from_secs(2);
|
|
|
|
let mut enigo = Enigo::new();
|
|
|
|
|
|
|
|
thread::sleep(wait_time);
|
|
|
|
|
|
|
|
enigo.mouse_move_to(500, 200);
|
|
|
|
thread::sleep(wait_time);
|
|
|
|
|
2023-06-07 20:16:31 +08:00
|
|
|
enigo.mouse_down(MouseButton::Left).ok();
|
|
|
|
thread::sleep(wait_time);
|
|
|
|
|
|
|
|
enigo.mouse_move_relative(100, 100);
|
|
|
|
thread::sleep(wait_time);
|
|
|
|
|
|
|
|
enigo.mouse_up(MouseButton::Left);
|
|
|
|
thread::sleep(wait_time);
|
2021-03-29 15:59:14 +08:00
|
|
|
|
|
|
|
enigo.mouse_click(MouseButton::Left);
|
|
|
|
thread::sleep(wait_time);
|
|
|
|
|
2022-12-26 11:25:55 +08:00
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
|
|
{
|
2023-06-07 21:17:13 +08:00
|
|
|
#[cfg(windows)]
|
2023-06-07 20:01:01 +08:00
|
|
|
enigo.mouse_scroll_x(2 * WHEEL_DELTA as i32);
|
2023-06-07 21:17:13 +08:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
enigo.mouse_scroll_x(2);
|
2022-12-26 11:25:55 +08:00
|
|
|
thread::sleep(wait_time);
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2023-06-07 21:17:13 +08:00
|
|
|
#[cfg(windows)]
|
2023-06-07 20:01:01 +08:00
|
|
|
enigo.mouse_scroll_x(-2 * WHEEL_DELTA as i32);
|
2023-06-07 21:17:13 +08:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
enigo.mouse_scroll_x(-2);
|
2022-12-26 11:25:55 +08:00
|
|
|
thread::sleep(wait_time);
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2023-06-07 21:17:13 +08:00
|
|
|
#[cfg(windows)]
|
2023-06-07 20:01:01 +08:00
|
|
|
enigo.mouse_scroll_y(2 * WHEEL_DELTA as i32);
|
2023-06-07 21:17:13 +08:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
enigo.mouse_scroll_y(2);
|
2022-12-26 11:25:55 +08:00
|
|
|
thread::sleep(wait_time);
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2023-06-07 21:17:13 +08:00
|
|
|
#[cfg(windows)]
|
2023-06-07 20:01:01 +08:00
|
|
|
enigo.mouse_scroll_y(-2 * WHEEL_DELTA as i32);
|
2023-06-07 21:17:13 +08:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
enigo.mouse_scroll_y(-2);
|
2022-12-26 11:25:55 +08:00
|
|
|
thread::sleep(wait_time);
|
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|