small performance improvements
This commit is contained in:
parent
ac61409ef4
commit
4fd3ec98cc
|
@ -1,6 +1,6 @@
|
||||||
use winapi::um::winuser::GetKeyNameTextW;
|
use winapi::um::winuser::GetKeyNameTextW;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use wio::wide::FromWide;
|
use wio::wide::{FromWide, ToWide};
|
||||||
|
|
||||||
pub mod logger;
|
pub mod logger;
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ pub fn scan_code_to_key_name(scan_code: u32) -> String {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut out = [0u16; 128];
|
let mut out = [0u16; 128];
|
||||||
GetKeyNameTextW((scan_code << 16) as i32, (&mut out).as_mut_ptr(), 128);
|
GetKeyNameTextW((scan_code << 16) as i32, (&mut out).as_mut_ptr(), 128);
|
||||||
OsString::from_wide(&out).to_str().unwrap().replace('\0', "")
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue