improvements
This commit is contained in:
+1
-20
@@ -1,22 +1,3 @@
|
||||
pub mod consts;
|
||||
pub mod countdown;
|
||||
pub mod elevation;
|
||||
|
||||
use windows::Win32::UI::{
|
||||
Input::KeyboardAndMouse::GetAsyncKeyState,
|
||||
WindowsAndMessaging::{GetForegroundWindow, GetWindowTextW},
|
||||
};
|
||||
|
||||
pub fn is_window_focused(target_title: &str) -> bool {
|
||||
unsafe {
|
||||
let hwnd = GetForegroundWindow();
|
||||
let mut buffer: [u16; 512] = [0; 512];
|
||||
let length = GetWindowTextW(hwnd, &mut buffer);
|
||||
let current_title = String::from_utf16_lossy(&buffer[..length as usize]);
|
||||
current_title == target_title
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_key_pressed(key: i32) -> bool {
|
||||
unsafe { (GetAsyncKeyState(key) as i32 & 0x8000) != 0 }
|
||||
}
|
||||
pub mod win;
|
||||
|
||||
@@ -1,11 +1,34 @@
|
||||
use windows::{
|
||||
Win32::Foundation::{CloseHandle, HANDLE},
|
||||
Win32::Security::{GetTokenInformation, TOKEN_ELEVATION, TOKEN_QUERY, TokenElevation},
|
||||
Win32::System::Threading::{GetCurrentProcess, OpenProcessToken},
|
||||
Win32::UI::{Shell::ShellExecuteW, WindowsAndMessaging::SW_HIDE},
|
||||
Win32::{
|
||||
Foundation::{CloseHandle, HANDLE},
|
||||
Security::{GetTokenInformation, TOKEN_ELEVATION, TOKEN_QUERY, TokenElevation},
|
||||
System::Threading::{GetCurrentProcess, OpenProcessToken},
|
||||
UI::{
|
||||
Input::KeyboardAndMouse::GetAsyncKeyState,
|
||||
Shell::ShellExecuteW,
|
||||
WindowsAndMessaging::SW_HIDE,
|
||||
WindowsAndMessaging::{GetForegroundWindow, GetWindowTextW},
|
||||
},
|
||||
},
|
||||
core::{HSTRING, PCWSTR},
|
||||
};
|
||||
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
pub fn is_window_focused(target_title: &str) -> bool {
|
||||
unsafe {
|
||||
let hwnd = GetForegroundWindow();
|
||||
let mut buffer: [u16; 512] = [0; 512];
|
||||
let length = GetWindowTextW(hwnd, &mut buffer);
|
||||
let current_title = String::from_utf16_lossy(&buffer[..length as usize]);
|
||||
current_title == target_title
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_any_key_pressed(keys: &[u8]) -> bool {
|
||||
keys.iter()
|
||||
.any(|&key| unsafe { (i32::from(GetAsyncKeyState(i32::from(key))) & 0x8000) != 0 })
|
||||
}
|
||||
|
||||
pub fn elevate(closing: &mut bool) {
|
||||
let exe = std::env::current_exe().unwrap();
|
||||
unsafe {
|
||||
Reference in New Issue
Block a user