An opinionated, lightweight crate to handle system-wide hotkeys on windows
The windows-hotkeys
crate abstracts and handles all interactions with the winapi, including
registering hotkeys and handling the events. A hotkey manager instance is used to register key
combinations together with easy callbacks.
VK_*
constants) and Modifier Keys
(MOD_*
constants)VKey
s (Virtual Keys) and ModKey
s (Modifier Keys) from key name stringsHotkeyManager
instanceVKey
and one or more ModKey
s, together with a callback```rust use windowshotkeys::keys::{ModKey, VKey}; use windowshotkeys::HotkeyManager;
fn main() { let mut hkm = HotkeyManager::new();
hkm.register(VKey::A, &[ModKey::Alt], || {
println!("Hotkey ALT + A was pressed");
})
.unwrap();
hkm.event_loop();
} ```
Due to limitations in the windows API, hotkey events can only be received and unregistered on the
same thread as they were initially registered. This means that a HotkeyManager
instance can't be
moved between threads.
Using windows-hotkeys
with multithreading is still possible, but the HotkeyManager
must be
created and used on the same thread.
A possible solution to this limitation might be to have each HotkeyManager
run it's own thread in
the backgroud that is used to register, unregister and listen for hotkeys. This might be implemented
in the future and would provide a more ergonomic way to use the HotkeyManager
in general.