4 releases
Uses new Rust 2024
0.2.0 | Mar 16, 2025 |
---|---|
0.1.3 | Sep 16, 2024 |
0.1.2 | Sep 16, 2024 |
0.1.1 | Sep 16, 2024 |
#140 in Windows APIs
105 downloads per month
24KB
380 lines
Windows Key Listener
A Rust library for global keyboard event listening and hotkey management on Windows.
Usage
use windows_key_listener::KeyListener;
use std::{sync::Arc, time::Duration};
fn main() {
let listener = KeyListener::new();
// Register shortcuts
key_listener.listen(
"Ctrl + Shift + A",
Duration::from_millis(200),
Arc::new(|| {
on_key_pressed();
false // Return true to block the event
})
);
run_your_app();
// When finished, clean up
key_listener.unlisten();
}
Installation
Add this to your Cargo.toml
:
[dependencies]
windows-key-listener = "x.y.z"
License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
lib.rs
:
A Windows library for listening to global keyboard shortcuts.
Register global keyboard shortcuts as arbitrary chords and execute callbacks when they are triggered.
Logging
This library uses the log
crate for configurable logging.
Example
use windows_key_listener::KeyListener;
use std::{sync::Arc, time::Duration};
let listener = KeyListener::new();
// Listen for Ctrl+Shift+Z with 200ms debounce
match listener.listen(
"Ctrl + Shift + Z",
Duration::from_millis(200),
Arc::new(|| {
println!("Shortcut triggered!");
false // Return true to block the key event
})
) {
Ok(_) => println!("Shortcut registered successfully"),
Err(e) => eprintln!("Failed to register shortcut: {}", e),
}
// Run the message loop to process key events
listener.run_message_loop();
Dependencies
~115MB
~2M SLoC