mirror of
https://github.com/tauri-apps/global-hotkey.git
synced 2026-01-31 00:45:22 +01:00
c530be0dbf939d2dd8d05eacc2071f493769a834
* feat: support registering media play/pause/stop/next/prev keys closes #70 * feat(macos): register media keys (#72) * feat(macos): register media keys * chore: update documents * organize codes * fix: using RefCell for event_tap * docs: remove mut from GlobalHotKeyManager::new() * use mutex and stop watching media keys on drop --------- Co-authored-by: Jason Tsai <jason@pews.dev>
global_hotkey lets you register Global HotKeys for Desktop Applications.
Platforms-supported:
- Windows
- macOS
- Linux (X11 Only)
Platform-specific notes:
- On Windows a win32 event loop must be running on the thread. It doesn't need to be the main thread but you have to create the global hotkey manager on the same thread as the event loop.
- On macOS, an event loop must be running on the main thread so you also need to create the global hotkey manager on the main thread.
Example
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);
Processing global hotkey events
You can also listen for the menu events using GlobalHotKeyEvent::receiver to get events for the hotkey pressed events.
use global_hotkey::GlobalHotKeyEvent;
if let Ok(event) = GlobalHotKeyEvent::receiver().try_recv() {
println!("{:?}", event);
}
License
Apache-2.0/MIT
Description
⚠️ ARCHIVED: Original GitHub repository no longer exists. Preserved as backup on 2026-01-31T05:32:04.887Z
Languages
Rust
100%