add a mouse cursor check to anti afk activation

This commit is contained in:
2025-04-16 23:59:50 +01:00
parent 5fe697223c
commit 284c4bb46d
3 changed files with 27 additions and 7 deletions
+8 -3
View File
@@ -25,10 +25,15 @@ impl Default for AntiAfk {
} }
impl 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) { pub fn activate(&mut self) {
if util::win::is_window_focused(GTA_WINDOW_TITLE) if self.can_activate() {
&& !util::win::is_any_key_pressed(&PRESS_KEYS)
{
send(&PRESS_KEYS); send(&PRESS_KEYS);
} }
self.interval = Instant::now(); self.interval = Instant::now();
+4 -3
View File
@@ -271,11 +271,12 @@ impl App {
} }
fn show_debug(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) { fn show_debug(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
ui.collapsing("times", |ui| { ui.collapsing("anti afk", |ui| {
ui.label(format!( ui.label(format!(
"anti afk timer: {}", "timer: {}",
self.anti_afk.interval.elapsed().as_secs() self.anti_afk.interval.elapsed().as_secs()
)) ));
ui.label(format!("can activate: {}", self.anti_afk.can_activate()));
}); });
ui.collapsing("sysinfo", |ui| { ui.collapsing("sysinfo", |ui| {
if ui.button("refresh all").clicked() { if ui.button("refresh all").clicked() {
+15 -1
View File
@@ -6,7 +6,10 @@ use windows::{
UI::{ UI::{
Input::KeyboardAndMouse::GetAsyncKeyState, Input::KeyboardAndMouse::GetAsyncKeyState,
Shell::ShellExecuteW, Shell::ShellExecuteW,
WindowsAndMessaging::{GetForegroundWindow, GetWindowTextW, SW_NORMAL}, WindowsAndMessaging::{
CURSOR_SHOWING, CURSORINFO, GetCursorInfo, GetForegroundWindow, GetWindowTextW,
SW_NORMAL,
},
}, },
}, },
core::{HSTRING, PCWSTR}, core::{HSTRING, PCWSTR},
@@ -17,6 +20,17 @@ pub enum ElevationExitMethod<'a> {
Forced, Forced,
} }
pub fn is_cursor_visible() -> bool {
let mut ci = CURSORINFO {
cbSize: std::mem::size_of::<CURSORINFO>() as u32,
..Default::default()
};
unsafe {
GetCursorInfo(&mut ci).unwrap();
}
ci.flags == CURSOR_SHOWING
}
#[allow(clippy::cast_sign_loss)] #[allow(clippy::cast_sign_loss)]
pub fn is_window_focused(target_title: &str) -> bool { pub fn is_window_focused(target_title: &str) -> bool {
unsafe { unsafe {