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
impl PauseHandle
Sourcepub fn toggle(&self)
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}Trait Implementations§
Source§impl Clone for PauseHandle
impl Clone for PauseHandle
Source§fn clone(&self) -> PauseHandle
fn clone(&self) -> PauseHandle
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PauseHandle
impl RefUnwindSafe for PauseHandle
impl Send for PauseHandle
impl Sync for PauseHandle
impl Unpin for PauseHandle
impl UnwindSafe for PauseHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more