16 lines
622 B
Rust
16 lines
622 B
Rust
use winapi::um::winuser::GetKeyNameTextW;
|
|
use std::ffi::OsString;
|
|
use wio::wide::{FromWide, ToWide};
|
|
|
|
pub mod logger;
|
|
|
|
#[no_mangle]
|
|
pub fn scan_code_to_key_name(scan_code: u32) -> String {
|
|
unsafe {
|
|
let mut out = [0u16; 128];
|
|
GetKeyNameTextW((scan_code << 16) as i32, (&mut out).as_mut_ptr(), 128);
|
|
let null_pos = out.iter().position(|x| *x == b'\0' as u16).unwrap_or_else(|| out.len());
|
|
//use to_string_lossy to avoid unicode checks for better performance. if the windows api screws up thats not my fault :P
|
|
OsString::from_wide(&out[..null_pos]).to_string_lossy().into()
|
|
}
|
|
} |