Skip to main content

HotkeyListener

Struct HotkeyListener 

Source
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

Source

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).

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.