init
This commit is contained in:
commit
c0e452f420
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/target
|
||||
.idea
|
||||
*.iml
|
40
Cargo.lock
generated
Normal file
40
Cargo.lock
generated
Normal file
|
@ -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",
|
||||
]
|
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "jenslog-rs"
|
||||
version = "0.1.0"
|
||||
authors = ["LordMZTE <lord@mzte.de>"]
|
||||
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"
|
30
src/main.rs
Normal file
30
src/main.rs
Normal file
|
@ -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', "")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue