Windows Hotkeys

Crates.io Crates.io Docs.rs

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.

Features

How to use

  1. Create a HotkeyManager instance
  2. Register a hokey by specifying a VKey and one or more ModKeys, together with a callback
  3. Run the event loop to react to the incomming hotkey triggers

```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();

} ```

Current limitations

Threading

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.