HotkeyManagerImpl

Trait HotkeyManagerImpl 

Source
pub trait HotkeyManagerImpl<T> {
    // Required methods
    fn new() -> Self;
    fn register_extrakeys(
        &mut self,
        virtual_key: VirtualKey,
        modifiers_key: Option<&[ModifiersKey]>,
        extra_keys: Option<&[VirtualKey]>,
        callback: Option<impl Fn() -> T + Send + 'static>,
    ) -> Result<HotkeyId, HotkeyError>;
    fn register(
        &mut self,
        virtual_key: VirtualKey,
        modifiers_key: Option<&[ModifiersKey]>,
        callback: Option<impl Fn() -> T + Send + 'static>,
    ) -> Result<HotkeyId, HotkeyError>;
    fn unregister(&mut self, id: HotkeyId) -> Result<(), HotkeyError>;
    fn unregister_all(&mut self) -> Result<(), HotkeyError>;
    fn handle_hotkey(&self) -> Option<T>;
    fn event_loop(&self);
    fn interrupt_handle(&self) -> InterruptHandle;
}

Required Methods§

Source

fn new() -> Self

Source

fn register_extrakeys( &mut self, virtual_key: VirtualKey, modifiers_key: Option<&[ModifiersKey]>, extra_keys: Option<&[VirtualKey]>, callback: Option<impl Fn() -> T + Send + 'static>, ) -> Result<HotkeyId, HotkeyError>

Register a new hotkey with additional required extra keys.

This will try to register the specified hotkey with windows, but not actively listen for it. To listen for hotkeys in order to actually execute the callbacks, the event_loop function must be called.

§Arguments
  • key - The main hotkey. For example VKey::Return for the CTRL + ALT + ENTER combination.

  • key_modifiers - The modifier keys that need to be combined with the main key. The modifier keys are the keys that need to be pressed in addition to the main hotkey in order for the hotkey event to fire. For example &[ModKey::Ctrl, ModKey::Alt] for the CTRL + ALT + ENTER combination.

  • extra_keys - A list of additional VKeys that also need to be pressed for the hotkey callback to be executed. This is enforced after the windows hotkey event is fired, but before executing the callback. So these keys need to be pressed before the main hotkey.

  • callback - A callback function or closure that will be executed when the hotkey is triggered. The return type for all callbacks in the same HotkeyManager must be the same.

§Windows API Functions used
Source

fn register( &mut self, virtual_key: VirtualKey, modifiers_key: Option<&[ModifiersKey]>, callback: Option<impl Fn() -> T + Send + 'static>, ) -> Result<HotkeyId, HotkeyError>

Same as register_extrakeys but without extra keys.

§Windows API Functions used
Source

fn unregister(&mut self, id: HotkeyId) -> Result<(), HotkeyError>

Unregister a hotkey. This will prevent the hotkey from being triggered in the future.

§Windows API Functions used
Source

fn unregister_all(&mut self) -> Result<(), HotkeyError>

Unregister all registered hotkeys. This will be called automatically when dropping the HotkeyManager instance.

§Windows API Functions used
Source

fn handle_hotkey(&self) -> Option<T>

Wait for a single a hotkey event and execute the callback if all keys match. This returns the callback result if it was not interrupted. The function call will block until a hotkey is triggered or it is interrupted.

If the event is interrupted, None is returned, otherwise Some is returned with the return value of the executed callback function.

§Windows API Functions used
Source

fn event_loop(&self)

Run the event loop, listening for hotkeys. This will run indefinitely until interrupted and execute any hotkeys registered before.

Source

fn interrupt_handle(&self) -> InterruptHandle

Get an InterruptHandle for this HotkeyManager that can be used to interrupt the event loop.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> HotkeyManagerImpl<T> for win_hotkey::single_thread::HotkeyManager<T>

Source§

impl<T: 'static + Send> HotkeyManagerImpl<T> for win_hotkey::thread_safe::HotkeyManager<T>