pub struct HotkeyListener { /* private fields */ }Expand description
Global hotkey listener. Constructed on the thread that owns the platform run loop; never moved across threads.
Implementations§
Source§impl HotkeyListener
impl HotkeyListener
Sourcepub fn start(accelerator: &str) -> Result<Self>
pub fn start(accelerator: &str) -> Result<Self>
Validate the accelerator string and register it with the OS.
§Errors
Returns an error when the accelerator string is malformed or when the OS rejects the registration (e.g. the combination is already claimed by another app).
Sourcepub fn poll(&self) -> Option<HotkeyEvent>
pub fn poll(&self) -> Option<HotkeyEvent>
Drain pending hotkey events without blocking, returning the
first stop request that matches the registered ID and press
half-cycle. Returns None when the queue is empty.
Sourcepub fn presses(&self) -> Presses
pub fn presses(&self) -> Presses
A handle to this hotkey’s presses that can leave this thread.
The listener cannot: GlobalHotKeyManager is !Send on macOS,
because its Carbon event handler is keyed to the thread that
created it. The press queue is a different thing — an ordinary
crossbeam receiver — and a host whose event loop is not its
own needs to read it from somewhere other than the thread the
listener is pinned to. Registration stays where it must be;
reading moves.