PauseHandle

Struct PauseHandle 

Source
pub struct PauseHandle { /* private fields */ }
Expand description

A handle for signaling the HotkeyManager to stop processing hotkeys without exiting the event loop or unregistering hotkeys. When paused, the HotkeyManager will only process registered pause hotkeys.

The PauseHandle is used to manage the pause state of the HotkeyManager.

Implementations§

Source§

impl PauseHandle

Source

pub fn toggle(&self)

Toggles the pause state of the HotkeyManager.

If the HotkeyManager is currently paused, calling this method will resume normal hotkey processing. If it is active, calling this method will pause it.

Examples found in repository?
examples/handles.rs (line 28)
6fn main() {
7    // Create the manager
8    let mut hkm = HotkeyManager::new();
9
10    // Register a system-wide hotkey with trigger key 'A' and modifier key 'CTRL'
11    hkm.register_hotkey(VKey::A, &[VKey::Control], || {
12        println!("Hotkey CTRL + A was pressed");
13    })
14    .unwrap();
15
16    // Get an interrupt handle that can be used to interrupt / stop the event loop from any thread
17    let interrupt_handle = hkm.interrupt_handle();
18
19    // Get a pause handle that can be used to programmatically pause the processing of hotkeys from
20    // any thread. Note: registered pause hotkeys will still be processed.
21    let pause_handle = hkm.pause_handle();
22
23    // Create a second thread that will pause/interrupt hkm
24    spawn(move || {
25        sleep(Duration::from_secs(3));
26
27        println!("Pausing hotkeys for 3 seconds");
28        pause_handle.toggle();
29        sleep(Duration::from_secs(3));
30
31        println!("Unpausing hotkeys");
32        pause_handle.toggle();
33
34        sleep(Duration::from_secs(3));
35        interrupt_handle.interrupt();
36    });
37
38    // Run the event handler in a blocking loop. This will block until interrupted and execute the
39    // set callbacks when registered hotkeys are detected
40    hkm.event_loop();
41
42    println!("Event Loop interrupted");
43}
Source

pub fn set(&self, state: bool)

Explicitly sets the pause state.

Source

pub fn is_paused(&self) -> bool

Returns whether the HotkeyManager is currently paused.

When paused, only pause hotkeys will be processed while all others will be ignored.

Trait Implementations§

Source§

impl Clone for PauseHandle

Source§

fn clone(&self) -> PauseHandle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PauseHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.