change how vks are stored

This commit is contained in:
2025-04-18 05:26:28 +01:00
parent 668a6eb38b
commit 64e94bf790
2 changed files with 20 additions and 11 deletions
+17 -8
View File
@@ -1,11 +1,12 @@
use crate::util::{self, consts::game::WINDOW_TITLE}; use crate::util::{self, consts::game::WINDOW_TITLE};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use windows::Win32::UI::Input::KeyboardAndMouse::{ use windows::Win32::UI::Input::KeyboardAndMouse::{
KEYBD_EVENT_FLAGS, MAP_VIRTUAL_KEY_TYPE, MapVirtualKeyW, VK_NUMPAD4, VK_NUMPAD6, keybd_event, KEYBD_EVENT_FLAGS, MAP_VIRTUAL_KEY_TYPE, MapVirtualKeyW, VIRTUAL_KEY, VK_NUMPAD4, VK_NUMPAD6,
keybd_event,
}; };
pub const INTERVAL: Duration = Duration::from_secs(60); pub const INTERVAL: Duration = Duration::from_secs(60);
const PRESS_KEYS: [u8; 2] = [VK_NUMPAD4.0 as u8, VK_NUMPAD6.0 as u8]; const PRESS_KEYS: [VIRTUAL_KEY; 2] = [VK_NUMPAD4, VK_NUMPAD6];
#[derive(Debug)] #[derive(Debug)]
pub struct AntiAfk { pub struct AntiAfk {
@@ -36,17 +37,25 @@ pub fn can_activate() -> bool {
is_window_focused(WINDOW_TITLE) && !is_any_key_pressed(&PRESS_KEYS) && !is_cursor_visible() is_window_focused(WINDOW_TITLE) && !is_any_key_pressed(&PRESS_KEYS) && !is_cursor_visible()
} }
pub fn send(vk_codes: &[u8]) { pub fn send(vk_codes: &[VIRTUAL_KEY]) {
vk_codes.iter().for_each(|vk_code: &u8| unsafe { vk_codes.iter().for_each(|vk_code| unsafe {
keybd_event( keybd_event(
*vk_code, vk_code.0 as u8,
u8::try_from(MapVirtualKeyW(u32::from(*vk_code), MAP_VIRTUAL_KEY_TYPE(0))).unwrap(), u8::try_from(MapVirtualKeyW(
u32::from(vk_code.0),
MAP_VIRTUAL_KEY_TYPE(0),
))
.unwrap(),
KEYBD_EVENT_FLAGS(0), KEYBD_EVENT_FLAGS(0),
0, 0,
); );
keybd_event( keybd_event(
*vk_code, vk_code.0 as u8,
u8::try_from(MapVirtualKeyW(u32::from(*vk_code), MAP_VIRTUAL_KEY_TYPE(0))).unwrap(), u8::try_from(MapVirtualKeyW(
u32::from(vk_code.0),
MAP_VIRTUAL_KEY_TYPE(0),
))
.unwrap(),
KEYBD_EVENT_FLAGS(2), KEYBD_EVENT_FLAGS(2),
0, 0,
); );
+3 -3
View File
@@ -4,7 +4,7 @@ use windows::{
Security::{GetTokenInformation, TOKEN_ELEVATION, TOKEN_QUERY, TokenElevation}, Security::{GetTokenInformation, TOKEN_ELEVATION, TOKEN_QUERY, TokenElevation},
System::Threading::{GetCurrentProcess, OpenProcessToken}, System::Threading::{GetCurrentProcess, OpenProcessToken},
UI::{ UI::{
Input::KeyboardAndMouse::GetAsyncKeyState, Input::KeyboardAndMouse::{GetAsyncKeyState, VIRTUAL_KEY},
Shell::ShellExecuteW, Shell::ShellExecuteW,
WindowsAndMessaging::{ WindowsAndMessaging::{
CURSOR_SHOWING, CURSORINFO, GetCursorInfo, GetForegroundWindow, GetWindowTextW, CURSOR_SHOWING, CURSORINFO, GetCursorInfo, GetForegroundWindow, GetWindowTextW,
@@ -41,9 +41,9 @@ pub fn is_window_focused(target_title: &str) -> bool {
} }
} }
pub fn is_any_key_pressed(keys: &[u8]) -> bool { pub fn is_any_key_pressed(keys: &[VIRTUAL_KEY]) -> bool {
keys.iter() keys.iter()
.any(|&key| unsafe { (GetAsyncKeyState(i32::from(key)) & i16::MIN) != 0 }) .any(|&key| unsafe { (GetAsyncKeyState(i32::from(key.0)) & i16::MIN) != 0 })
} }
pub fn elevate(closing: ElevationExitMethod) { pub fn elevate(closing: ElevationExitMethod) {