Register Global HotKeys
devTo register a global hotkey, you must first initialize a GlobalHotKeyManager, construct a HotKey using specific Modifiers and a Code, and then call register on the manager.
Platform Requirements:
- Windows: A win32 event loop must be running on the thread. The
GlobalHotKeyManagermust be created on the same thread as that event loop (not necessarily the main thread). - macOS: An event loop must be running on the main thread. You must create the
GlobalHotKeyManageron the main thread. - Linux: Supported on X11 only.
use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}};
// initialize the hotkeys manager
let manager = GlobalHotKeyManager::new().unwrap();
// construct the hotkey
let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD);
// register it
manager.register(hotkey);