redesign how anti afk activates
This commit is contained in:
+12
-10
@@ -5,7 +5,7 @@ use windows::Win32::UI::Input::KeyboardAndMouse::{
|
||||
keybd_event,
|
||||
};
|
||||
|
||||
pub const INTERVAL: Duration = Duration::from_secs(60);
|
||||
const INTERVAL: Duration = Duration::from_secs(60);
|
||||
const PRESS_KEYS: [VIRTUAL_KEY; 2] = [VK_NUMPAD4, VK_NUMPAD6];
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -24,19 +24,21 @@ impl Default for AntiAfk {
|
||||
}
|
||||
|
||||
impl AntiAfk {
|
||||
pub fn activate(&mut self) {
|
||||
if can_activate() {
|
||||
send(&PRESS_KEYS);
|
||||
}
|
||||
self.interval = Instant::now();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn can_activate() -> bool {
|
||||
pub fn can_activate(&self) -> bool {
|
||||
use util::win::{is_any_key_pressed, is_cursor_visible, is_window_focused};
|
||||
is_window_focused(WINDOW_TITLE) && !is_any_key_pressed(&PRESS_KEYS) && !is_cursor_visible()
|
||||
}
|
||||
|
||||
pub fn should_activate(&self) -> bool {
|
||||
self.enabled && self.interval.elapsed() >= INTERVAL
|
||||
}
|
||||
|
||||
pub fn activate(&mut self) {
|
||||
send(&PRESS_KEYS);
|
||||
self.interval = Instant::now();
|
||||
}
|
||||
}
|
||||
|
||||
fn send(vk_codes: &[VIRTUAL_KEY]) {
|
||||
vk_codes.iter().for_each(|vk_code| unsafe {
|
||||
keybd_event(
|
||||
|
||||
+2
-3
@@ -137,8 +137,7 @@ impl App {
|
||||
});
|
||||
}
|
||||
});
|
||||
if self.anti_afk.enabled && self.anti_afk.interval.elapsed() >= features::anti_afk::INTERVAL
|
||||
{
|
||||
if self.anti_afk.can_activate() && self.anti_afk.should_activate() {
|
||||
self.anti_afk.activate();
|
||||
}
|
||||
}
|
||||
@@ -269,7 +268,7 @@ impl App {
|
||||
));
|
||||
ui.label(format!(
|
||||
"can activate: {}",
|
||||
features::anti_afk::can_activate()
|
||||
self.anti_afk.can_activate()
|
||||
));
|
||||
});
|
||||
ui.collapsing("sysinfo", |ui| {
|
||||
|
||||
Reference in New Issue
Block a user