-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathmove_mouse.rs
More file actions
30 lines (25 loc) · 1.19 KB
/
move_mouse.rs
File metadata and controls
30 lines (25 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::{thread::sleep, time::Duration};
use inputbot::{KeybdKey::*, MouseCursor};
/// This example demonstrates moving the mouse around on the screen both relative to its position,
/// and absolute. To use these functions effectively, you would ideally combine it with a library
/// which exposes your system display resolution, as well as separates different monitors.
fn main() {
// Bind our 1 key to a function that moves the mouse absolute to your monitors. Note: if you
// have multiple monitors, 0, 0 might be not where you're expecting. If we wanted to get the
// absolute position of your primary (or a specific) monitor, we would need to bring in extra
// libraries.
Numrow1Key.bind(|| {
for x in 0..=600 {
MouseCursor::move_abs(x, 300);
sleep(Duration::from_millis(1));
}
});
// Bind our 2 key to a function that moves the mouse relative to its current position.
// This will be 100 pixels over and 100 pixels down.
Numrow2Key.bind(|| {
MouseCursor::move_rel(100, 100);
sleep(Duration::from_millis(1));
});
// Call this to start listening for bound inputs.
inputbot::handle_input_events(false);
}