jenslog-rs/src/lib.rs
LordMZTE 9e78b067f5 move keystate into own file
configure clippy linter
adjust style to linter settings
2020-08-26 13:51:43 +02:00

28 lines
1,022 B
Rust

//region Clippy config
#![warn(clippy::pedantic)]
//disable silly rules
#![allow(
clippy::module_name_repetitions, //complains about function names which makes no sense, so disabled
clippy::must_use_candidate, //no i dont wannt to add the must_use attribute to everything
clippy::cast_lossless, clippy::cast_possible_wrap, //lossy casts are required to work with garbage WinApi
)]
//endregion
use winapi::um::winuser::GetKeyNameTextW;
use std::ffi::OsString;
use wio::wide::FromWide;
pub mod logging;
pub mod key;
#[no_mangle]
pub fn scan_code_to_key_name(scan_code: u32) -> String {
unsafe {
let mut out = [0_u16; 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()
}
}