Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit a2fb550

Browse files
committed
Implement natural mouse movement
- Updated the ‘simulate_activity’ function to simulate a gradual mouse movement with a square pattern.
1 parent 797b458 commit a2fb550

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/lib.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,37 @@ pub struct KeepActive {
8080
_imp: sys::KeepActive,
8181
}
8282

83-
// TODO: gradual movement
84-
// exit gracefully on Ctrl+C
83+
// TODO: exit gracefully on Ctrl+C
8584
pub fn simulate_activity() -> Result<(), Box<dyn std::error::Error>> {
8685
let mut enigo = Enigo::new();
8786

8887
loop {
89-
enigo.mouse_move_relative(100, 100);
90-
thread::sleep(Duration::from_secs(1));
91-
enigo.mouse_move_relative(-100, -100);
88+
// Move right
89+
for _ in 0..10 {
90+
enigo.mouse_move_relative(1, 0);
91+
thread::sleep(Duration::from_millis(100));
92+
}
93+
// Move down
94+
for _ in 0..10 {
95+
enigo.mouse_move_relative(0, 1);
96+
thread::sleep(Duration::from_millis(100));
97+
}
98+
// Move left
99+
for _ in 0..10 {
100+
enigo.mouse_move_relative(-1, 0);
101+
thread::sleep(Duration::from_millis(100));
102+
}
103+
// Move up
104+
for _ in 0..10 {
105+
enigo.mouse_move_relative(0, -1);
106+
thread::sleep(Duration::from_millis(100));
107+
}
92108

109+
// Simulate a key press to keep activity
93110
enigo.key_down(Key::Shift);
94111
enigo.key_up(Key::Shift);
95112

96-
thread::sleep(Duration::from_secs(2)); // TODO: make this configurable
113+
thread::sleep(Duration::from_secs(60)); // TODO: Make this configurable
97114
}
98115
}
116+

0 commit comments

Comments
 (0)