From 284c4bb46d566b5166397c8b48797a3c8e845a2a Mon Sep 17 00:00:00 2001 From: futile Date: Wed, 16 Apr 2025 23:59:50 +0100 Subject: [PATCH] add a mouse cursor check to anti afk activation --- src/features/anti_afk.rs | 11 ++++++++--- src/gui/mod.rs | 7 ++++--- src/util/win.rs | 16 +++++++++++++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/features/anti_afk.rs b/src/features/anti_afk.rs index 0e72c33..0c58245 100644 --- a/src/features/anti_afk.rs +++ b/src/features/anti_afk.rs @@ -25,10 +25,15 @@ impl Default for AntiAfk { } impl AntiAfk { + pub fn can_activate(&self) -> bool { + use util::win::*; + is_window_focused(GTA_WINDOW_TITLE) + && !is_any_key_pressed(&PRESS_KEYS) + && !is_cursor_visible() + } + pub fn activate(&mut self) { - if util::win::is_window_focused(GTA_WINDOW_TITLE) - && !util::win::is_any_key_pressed(&PRESS_KEYS) - { + if self.can_activate() { send(&PRESS_KEYS); } self.interval = Instant::now(); diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 14fe813..10cbcbd 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -271,11 +271,12 @@ impl App { } fn show_debug(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) { - ui.collapsing("times", |ui| { + ui.collapsing("anti afk", |ui| { ui.label(format!( - "anti afk timer: {}", + "timer: {}", self.anti_afk.interval.elapsed().as_secs() - )) + )); + ui.label(format!("can activate: {}", self.anti_afk.can_activate())); }); ui.collapsing("sysinfo", |ui| { if ui.button("refresh all").clicked() { diff --git a/src/util/win.rs b/src/util/win.rs index 64d1483..3dfb931 100644 --- a/src/util/win.rs +++ b/src/util/win.rs @@ -6,7 +6,10 @@ use windows::{ UI::{ Input::KeyboardAndMouse::GetAsyncKeyState, Shell::ShellExecuteW, - WindowsAndMessaging::{GetForegroundWindow, GetWindowTextW, SW_NORMAL}, + WindowsAndMessaging::{ + CURSOR_SHOWING, CURSORINFO, GetCursorInfo, GetForegroundWindow, GetWindowTextW, + SW_NORMAL, + }, }, }, core::{HSTRING, PCWSTR}, @@ -17,6 +20,17 @@ pub enum ElevationExitMethod<'a> { Forced, } +pub fn is_cursor_visible() -> bool { + let mut ci = CURSORINFO { + cbSize: std::mem::size_of::() as u32, + ..Default::default() + }; + unsafe { + GetCursorInfo(&mut ci).unwrap(); + } + ci.flags == CURSOR_SHOWING +} + #[allow(clippy::cast_sign_loss)] pub fn is_window_focused(target_title: &str) -> bool { unsafe {