### Register Hotkey Example Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/errors.md Example function demonstrating how to register a hotkey, returning a Result. ```rust fn register_hotkey(manager: &GlobalHotKeyManager, hotkey: HotKey) -> Result<()> { manager.register(hotkey)? } ``` -------------------------------- ### Minimal Global Hotkey Setup Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/configuration.md This is the most basic setup for registering a global hotkey. It requires only the GlobalHotKeyManager and HotKey types. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}}; fn main() -> Result<()> { let manager = GlobalHotKeyManager::new()?; let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); manager.register(hotkey)?; Ok(()) } ``` -------------------------------- ### HotKey Creation Examples Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Demonstrates how to create HotKey instances with different modifier combinations and key codes. ```rust use global_hotkey::hotkey::{HotKey, Modifiers, Code}; // Shift+D let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); // No modifiers, just F key let hotkey = HotKey::new(None, Code::KeyF); // Multiple modifiers with bitwise OR let hotkey = HotKey::new( Some(Modifiers::CONTROL | Modifiers::ALT), Code::KeyS ); ``` -------------------------------- ### Setup GlobalHotKeyManager on Linux (X11) Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/configuration.md The X11 connection happens internally in a spawned thread. This setup is suitable for Linux environments using the X11 display server. ```rust use global_hotkey::GlobalHotKeyManager; // X11 connection happens internally in a spawned thread let manager = GlobalHotKeyManager::new()?; ``` -------------------------------- ### Example: Save Hotkey with Modifiers Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Modifiers.md Demonstrates creating a hotkey with a combination of Control and Shift modifiers. ```rust let save_hotkey = HotKey::new( Some(Modifiers::CONTROL | Modifiers::SHIFT), Code::KeyS ); ``` -------------------------------- ### Create GlobalHotKeyManager Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Instantiate the GlobalHotKeyManager. This is the starting point for managing hotkeys. ```rust GlobalHotKeyManager::new()? ``` -------------------------------- ### Hotkey String Parsing Examples Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Illustrates various valid string formats for defining hotkeys, including combinations of modifiers and different key types. ```text "shift+KeyD" ``` ```text "ctrl+alt+E" ``` ```text "super+shift+Enter" ``` ```text "ctrl+/" ``` -------------------------------- ### Cargo.toml Dependencies Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/configuration.md Example configurations for adding the `global-hotkey` crate to your `Cargo.toml` file, including optional features. ```toml [dependencies] global-hotkey = "0.8" ``` ```toml [dependencies] global-hotkey = { version = "0.8", features = ["serde", "tracing"] } ``` -------------------------------- ### Register Hotkey Example Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/INDEX.md Demonstrates how to create a GlobalHotKeyManager, define a hotkey with modifiers (SHIFT) and a key code (KeyD), and register it. This pattern is fundamental for setting up hotkeys. ```rust let mgr = GlobalHotKeyManager::new()?; let hk = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); mgr.register(hk)?; ``` -------------------------------- ### Platform-Aware Hotkey Setup Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Modifiers.md Set up hotkeys with platform-specific modifiers (e.g., Super on macOS, Control on other OSs). Imports `CMD_OR_CTRL` for a concise cross-platform approach. ```rust use global_hotkey::hotkey::{HotKey, Modifiers, CMD_OR_CTRL, Code}; #[cfg(target_os = "macos")] let undo = HotKey::new(Some(Modifiers::SUPER), Code::KeyZ); #[cfg(not(target_os = "macos"))] let undo = HotKey::new(Some(Modifiers::CONTROL), Code::KeyZ); // Or more concisely: let undo = HotKey::new(Some(CMD_OR_CTRL), Code::KeyZ); ``` -------------------------------- ### Hotkey String Format Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Explains the structure and rules for formatting hotkey strings, including valid examples and parsing logic. ```APIDOC ## Parsing ### String Format Hotkey strings use `+` as a separator with modifiers appearing before the main key: ``` [modifier]+[modifier]+...+[key] ``` **Valid examples**: - `"KeyD"` — single key, no modifiers - `"shift+KeyD"` — shift modifier - `"control+alt+KeyQ"` — multiple modifiers - `"super+shift+Enter"` — super (command on macOS) and shift **Parsing Rules**: - Modifiers must appear before the main key - Only one main key is allowed - Case-insensitive for modifier names - Supported modifiers: `shift`, `control` (or `ctrl`), `alt` (or `option`), `super` (or `cmd`/`command`) - On macOS only: `commandorcontrol` (or `cmdorctrl`/`cmdorcontrol`) resolves to `super` - On non-macOS: `commandorcontrol` resolves to `control` **Error Cases**: - Empty tokens (e.g., `"shift++KeyD"`) - Invalid modifier order (e.g., `"shift+KeyD+alt"`) - Multiple main keys (e.g., `"shift+KeyD+KeyE"`) - Unrecognized key names ``` -------------------------------- ### Register Multiple Hotkeys Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Demonstrates registering multiple hotkeys simultaneously using the `register_all` method, providing an example with Control+D and Alt+E. ```rust let hotkeys = vec![ HotKey::new(Some(Modifiers::CONTROL), Code::KeyD), HotKey::new(Some(Modifiers::ALT), Code::KeyE), ]; manager.register_all(&hotkeys)?; ``` -------------------------------- ### Example Usage of Modifiers Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/types.md Demonstrates how to create a Modifiers bitset by combining Control and Shift, and how to check for the presence of specific modifier keys. ```rust use global_hotkey::hotkey::Modifiers; let mods = Modifiers::CONTROL | Modifiers::SHIFT; assert!(mods.contains(Modifiers::CONTROL)); assert!(mods.contains(Modifiers::SHIFT)); assert!(!mods.contains(Modifiers::ALT)); ``` -------------------------------- ### Cross-Platform Hotkey Setup Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Explains how to set up hotkeys that work cross-platform by using `CMD_OR_CTRL`. This automatically resolves to the appropriate modifier key (Cmd on macOS, Ctrl on other OSs). ```rust use global_hotkey::hotkey::CMD_OR_CTRL; // Automatically resolves to Cmd on macOS, Ctrl elsewhere let save = HotKey::new(Some(CMD_OR_CTRL), Code::KeyS); ``` -------------------------------- ### Handle Hotkey Registration Errors Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/INDEX.md Provides an example of how to handle potential errors during hotkey registration, specifically checking for `AlreadyRegistered` errors or other general errors. ```rust match mgr.register(hk) { Ok(()) => println!("Registered"), Err(Error::AlreadyRegistered(h)) => println!("Already registered"), Err(e) => eprintln!("Error: {}", e), } ``` -------------------------------- ### Setup GlobalHotKeyManager on macOS Main Thread Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/configuration.md Must be called on the main thread. macOS event handling is tied to the main thread, and accessibility permissions may be required for media keys. ```rust use global_hotkey::GlobalHotKeyManager; // This MUST be on the main thread let manager = GlobalHotKeyManager::new()?; ``` -------------------------------- ### Unsupported Hotkey String Formats Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Code.md Examples of string formats that will fail parsing with an `UnrecognizedHotKeyCode` error. This includes unknown keys, typos, and incorrect key names. ```rust // These will fail with UnrecognizedHotKeyCode error "InvalidKey".parse::() // Unknown key ``` ```rust "Keyz".parse::() // Typo (KeyZ not Keyz) ``` ```rust "MetaKey".parse::() // Use "Meta" or "Super" instead ``` -------------------------------- ### Creating a HotKey with Cross-Platform Modifiers Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Example of creating a HotKey using the CMD_OR_CTRL constant for platform-independent modifier behavior. This hotkey will be Cmd+S on macOS and Ctrl+S on Windows/Linux. ```rust use global_hotkey::hotkey::{HotKey, CMD_OR_CTRL, Code}; // Creates Cmd+S on macOS, Ctrl+S on Windows/Linux let save_hotkey = HotKey::new(Some(CMD_OR_CTRL), Code::KeyS); ``` -------------------------------- ### Setup GlobalHotKeyManager on Windows Event Loop Thread Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/configuration.md Must be called from within the Win32 event loop thread. Windows requires the hotkey manager to be created on the same thread as the event loop. ```rust use global_hotkey::GlobalHotKeyManager; fn setup_on_event_loop_thread() -> Result { // This MUST be called from within the Win32 event loop thread GlobalHotKeyManager::new() } ``` -------------------------------- ### Initialize Tracing for Logging Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/configuration.md After enabling the 'tracing' feature, initialize the tracing subscriber to begin logging errors and events. This setup is necessary for the tracing functionality to be active. ```rust use tracing_subscriber; tracing_subscriber::fmt::init(); // Now errors in platform-specific code will be logged ``` -------------------------------- ### Platform-Specific Media Key Hotkeys Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Code.md Define hotkeys for media keys, accounting for platform-specific `Code` variations. For example, 'PlayPause' might differ between macOS and other operating systems. ```rust use global_hotkey::hotkey::{HotKey, Modifiers, Code}; // Different media key codes per platform #[cfg(target_os = "macos")] let play_pause = HotKey::new(Some(Modifiers::SHIFT), Code::MediaPlayPause); #[cfg(not(target_os = "macos"))] let play_pause = HotKey::new(Some(Modifiers::SHIFT), Code::MediaPlay); let next_track = HotKey::new(Some(Modifiers::SHIFT), Code::MediaTrackNext); ``` -------------------------------- ### GlobalHotKeyEvent Handling Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/INDEX.md Provides access to hotkey activation events. Use the receiver to get events and optionally set a custom event handler. Events contain the hotkey ID and its state (pressed or released). ```rust GlobalHotKeyEvent::receiver() -> &'static Receiver ``` ```rust GlobalHotKeyEvent::set_event_handler(Option) ``` ```rust event.id() -> u32 ``` ```rust event.state() -> HotKeyState // Pressed or Released ``` -------------------------------- ### Register and Listen for a Hotkey Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Demonstrates the basic usage of creating a hotkey manager, registering a hotkey (Shift+D), and listening for its events in a loop. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}, GlobalHotKeyEvent}; fn main() -> Result<()> { // Create manager let manager = GlobalHotKeyManager::new()?; // Register a hotkey (Shift+D) let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); manager.register(hotkey)?; // Listen for events let receiver = GlobalHotKeyEvent::receiver(); loop { if let Ok(event) = receiver.try_recv() { println!("Hotkey {} was triggered", event.id()); } } } ``` -------------------------------- ### Get Event State Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Retrieve the state of a hotkey event, indicating whether the key was pressed or released. ```rust event.state() ``` -------------------------------- ### Get Event ID Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Retrieve the unique identifier for a hotkey event. This corresponds to the ID of the hotkey that triggered the event. ```rust event.id() ``` -------------------------------- ### Get Hotkey ID Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Retrieve the unique identifier for a HotKey object. This ID can be used for internal tracking or referencing. ```rust hotkey.id() ``` -------------------------------- ### Global Hotkey with Winit GUI Framework Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/configuration.md Demonstrates integrating global hotkeys with the Winit GUI library. It sets up an event loop and listens for hotkey events, printing them to the console. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}, GlobalHotKeyEvent}; use winit::event_loop::EventLoop; fn main() { let event_loop = EventLoop::new().unwrap(); let manager = GlobalHotKeyManager::new().unwrap(); let hotkey = HotKey::new(Some(Modifiers::ALT), Code::KeyE); manager.register(hotkey).unwrap(); let receiver = GlobalHotKeyEvent::receiver(); event_loop.run(move |event, _| { use winit::event::Event; match event { Event::AboutToWait => { if let Ok(hk_event) = receiver.try_recv() { println!("Event: {:?}", hk_event); } } _ => {} } }).unwrap(); } ``` -------------------------------- ### HotKey Display Implementation Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Demonstrates how to print a HotKey instance, which implements the Display trait for convenient string representation. ```APIDOC ## Display `HotKey` implements `Display` for convenient printing. ```rust let hotkey = HotKey::new(Some(Modifiers::ALT), Code::KeyE); println!("{}", hotkey); // Output: alt+KeyE ``` ``` -------------------------------- ### Get Hotkey State from Event Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/GlobalHotKeyEvent.md Determines whether the hotkey was pressed or released. This allows for differentiating between key down and key up actions. ```rust use global_hotkey::{GlobalHotKeyEvent, HotKeyState}; if let Ok(event) = GlobalHotKeyEvent::receiver().try_recv() { match event.state() { HotKeyState::Pressed => println!("Key pressed"), HotKeyState::Released => println!("Key released"), } } ``` -------------------------------- ### GUI Integration with Tao Framework Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Illustrates how to integrate global hotkey event handling within a GUI application using the Tao framework. It sets up an event loop and checks for hotkey presses. ```rust use tao::event_loop::{ControlFlow, EventLoopBuilder}; let event_loop = EventLoopBuilder::new().build(); let manager = GlobalHotKeyManager::new()?; let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); manager.register(hotkey)?; let receiver = GlobalHotKeyEvent::receiver(); event_loop.run(move |_event, _, control_flow| { *control_flow = ControlFlow::Poll; if let Ok(event) = receiver.try_recv() { if event.id() == hotkey.id() { println!("Hotkey pressed!"); } } }); ``` -------------------------------- ### Represent Media Keys and Platform Specifics Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Code.md Demonstrates representing media keys like PlayPause. Includes platform-specific conditional compilation for macOS and other operating systems, as media key representations can vary. ```rust let play_pause = Code::MediaPlayPause; let hotkey = "shift+MediaPlayPause".parse::()?; #[cfg(target_os = "macos")] let play = Code::MediaPlayPause; // macOS uses this #[cfg(not(target_os = "macos"))] let play = Code::MediaPlay; // Other platforms may use separate keys ``` -------------------------------- ### Get Hotkey ID from Event Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/GlobalHotKeyEvent.md Retrieves the unique identifier of the hotkey that triggered the event. This is useful for matching the event to a specific registered hotkey. ```rust use global_hotkey::GlobalHotKeyEvent; if let Ok(event) = GlobalHotKeyEvent::receiver().try_recv() { let hotkey_id = event.id(); println!("Hotkey {} was triggered", hotkey_id); } ``` -------------------------------- ### GlobalHotKeyManager::new Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/GlobalHotKeyManager.md Creates a new global hotkey manager instance. Platform-specific requirements must be met for initialization. ```APIDOC ## GlobalHotKeyManager::new ### Description Creates a new global hotkey manager instance. Platform-specific requirements must be met for initialization. ### Returns `Result` - A new manager instance or an error if initialization fails. ### Platform Requirements - **Windows**: A Win32 event loop must be running on the current thread. - **macOS**: An event loop must be running on the main thread. - **Linux (X11)**: A display connection is required. ### Throws - `Error::OsError`: If platform initialization fails. ### Example ```rust use global_hotkey::GlobalHotKeyManager; let manager = GlobalHotKeyManager::new()?; ``` ``` -------------------------------- ### Create Empty Modifiers Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Modifiers.md Creates a modifier set with no modifiers active. Use this as a starting point when you need a Modifiers value that represents no keys pressed. ```rust use global_hotkey::hotkey::Modifiers; let no_mods = Modifiers::empty(); assert!(!no_mods.contains(Modifiers::SHIFT)); ``` -------------------------------- ### Register a Global Hotkey Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Create a GlobalHotKeyManager and register a new hotkey combination. This is the primary method for setting up hotkeys. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}}; let manager = GlobalHotKeyManager::new()?; let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); manager.register(hotkey)?; ``` -------------------------------- ### Get Hotkey Event Receiver Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Obtain a channel receiver to listen for global hotkey events. This allows your application to react when hotkeys are pressed or released. ```rust let receiver = GlobalHotKeyEvent::receiver(); ``` -------------------------------- ### Get HotKey ID Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Retrieve the unique identifier for a hotkey. This ID is used internally for matching keyboard events and remains stable for the same hotkey combination. ```rust let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); let id = hotkey.id(); ``` -------------------------------- ### Register Multiple Hotkeys Programmatically Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Shows how to register multiple hotkeys simultaneously by creating a vector of HotKey objects and using the `register_all` method. This is efficient for setting up several key bindings at once. ```rust let hotkeys = vec![ HotKey::new(Some(Modifiers::CONTROL), Code::KeyD), HotKey::new(Some(Modifiers::ALT), Code::KeyE), HotKey::new(Some(Modifiers::SHIFT), Code::KeyF), ]; manager.register_all(&hotkeys)?; ``` -------------------------------- ### Create GlobalHotKeyManager Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Instantiate the primary API for managing global hotkeys. This method returns a Result, so error handling is required. ```rust let mut manager = GlobalHotKeyManager::new()?; ``` -------------------------------- ### Pattern 4: Integration with GUI Event Loop (Tao) Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/GlobalHotKeyEvent.md This pattern illustrates how to integrate global hotkey event handling into a GUI application's event loop, specifically using the Tao framework. It shows how to register hotkeys and react to their events within the main event loop. ```APIDOC ## Pattern 4: Integration with GUI Event Loop (Tao) This pattern illustrates how to integrate global hotkey event handling into a GUI application's event loop, specifically using the Tao framework. It shows how to register hotkeys and react to their events within the main event loop. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}, GlobalHotKeyEvent, HotKeyState}; use tao::event_loop::{ControlFlow, EventLoopBuilder}; let event_loop = EventLoopBuilder::new().build(); let manager = GlobalHotKeyManager::new()?; let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); manager.register(hotkey)?; let receiver = GlobalHotKeyEvent::receiver(); event_loop.run(move |_event, _, control_flow| { *control_flow = ControlFlow::Poll; if let Ok(event) = receiver.try_recv() { println!("Hotkey event: {:?}", event); if event.id() == hotkey.id() && event.state() == HotKeyState::Released { manager.unregister(hotkey).unwrap(); } } }); ``` ``` -------------------------------- ### Get Raw Bit Representation Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Modifiers.md Returns the underlying bitflags value as a raw integer. This is primarily used internally for computing hotkey IDs but can be useful for debugging or low-level operations. ```rust pub const fn bits(&self) -> u32 ``` -------------------------------- ### Integrating Hotkey Events with Tao GUI Event Loop Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/GlobalHotKeyEvent.md Demonstrates how to integrate hotkey event handling into a Tao-based GUI event loop. This pattern allows hotkey events to be processed alongside other UI events. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}, GlobalHotKeyEvent, HotKeyState}; use tao::event_loop::{ControlFlow, EventLoopBuilder}; let event_loop = EventLoopBuilder::new().build(); let manager = GlobalHotKeyManager::new()?; let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); manager.register(hotkey)?; let receiver = GlobalHotKeyEvent::receiver(); event_loop.run(move |_event, _, control_flow| { *control_flow = ControlFlow::Poll; if let Ok(event) = receiver.try_recv() { println!("Hotkey event: {:?}", event); if event.id() == hotkey.id() && event.state() == HotKeyState::Released { manager.unregister(hotkey).unwrap(); } } }); ``` -------------------------------- ### Create GlobalHotKeyManager Instance Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/GlobalHotKeyManager.md Instantiate a new GlobalHotKeyManager. Ensure platform-specific event loop requirements are met before calling. ```rust use global_hotkey::GlobalHotKeyManager; let manager = GlobalHotKeyManager::new()?; ``` -------------------------------- ### HotKey Definition and Matching Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/INDEX.md Defines a hotkey using modifiers and a key code, and provides methods to get its ID or check if it matches a given combination. Hotkeys can be created with or without modifiers. ```rust HotKey::new(Option, Code) -> HotKey ``` ```rust hotkey.id() -> u32 ``` ```rust hotkey.matches(Modifiers, Code) -> bool ``` -------------------------------- ### Register and Unregister a Single Hotkey Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Demonstrates the basic process of creating a GlobalHotKeyManager, registering a single hotkey, and unregistering it later. Ensure you handle potential errors during manager creation and registration. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}}; let manager = GlobalHotKeyManager::new()?; let hotkey = HotKey::new(Some(Modifiers::CONTROL), Code::KeyD); manager.register(hotkey)?; // Later... manager.unregister(hotkey)?; ``` -------------------------------- ### GlobalHotKeyManager::register_all Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/GlobalHotKeyManager.md Registers multiple hotkeys sequentially. If any registration fails, the error is returned immediately, but previously registered hotkeys from this call remain active. ```APIDOC ## GlobalHotKeyManager::register_all ### Description Registers multiple hotkeys in sequence. If any registration fails, the function returns the error immediately; previously registered hotkeys from this call remain registered. ### Parameters #### Path Parameters - **hotkeys** (`&[HotKey]`) - Required - A slice of hotkeys to register. ### Returns `Result<(), Error>` - An empty result on success, or an error if any registration fails. ### Throws - Same as `register()`. ### Example ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}}; let manager = GlobalHotKeyManager::new()?; let hotkeys = vec![ HotKey::new(Some(Modifiers::CONTROL), Code::KeyD), HotKey::new(Some(Modifiers::ALT), Code::KeyE), ]; manager.register_all(&hotkeys)?; ``` ``` -------------------------------- ### receiver() -> &GlobalHotKeyEventReceiver Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/GlobalHotKeyEvent.md Gets a reference to the global event receiver channel for all hotkey events. This returns a static reference that can be polled or used in a blocking receive loop. Events are only sent to this channel if no custom event handler has been set. ```APIDOC ## receiver() ### Description Gets a reference to the global event receiver channel for all hotkey events. This returns a static reference that can be polled or used in a blocking receive loop. Events are only sent to this channel if no custom event handler has been set with `set_event_handler()`. ### Returns - `&'static GlobalHotKeyEventReceiver`: A static reference to the event receiver channel. ``` -------------------------------- ### HotKey Methods Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Provides methods for creating and parsing HotKey objects. ```APIDOC ## HotKey::new(mods, key) ### Description Creates a new HotKey instance from modifiers and a key code. ### Method `HotKey::new(mods, key)` ### Parameters - **mods** (`Modifiers`) - Bitflags representing modifier keys (e.g., SHIFT, CONTROL). - **key** (`Code`) - The keyboard key code. ### Returns `HotKey` - The created HotKey object. ## HotKey::from_str(s) ### Description Parses a string representation into a HotKey object. ### Method `HotKey::from_str(s)` ### Parameters - **s** (`&str`) - The string to parse (e.g., "shift+KeyD"). ### Returns `Result` - A Result containing the parsed HotKey or an error if parsing fails. ### Key Parsing Format Hotkeys can be created from strings with the format: `[modifier]+[modifier]+...+[key]`. **Modifiers** (case-insensitive): `shift`, `control`, `alt`, `super`, `cmd`, `command`, `ctrl`, `option` **Keys** (case-insensitive): Letters (`A`-`Z`), Digits (`0`-`9`), Special keys (`Enter`, `Space`), Navigation keys (`ArrowUp`), Function keys (`F1`), Numpad keys (`Numpad0`), Symbols (`Comma`), Media keys (`MediaPlay`), Audio keys (`AudioVolumeUp`). **Examples**: - `"shift+KeyD"` - `"ctrl+alt+E"` - `"super+shift+Enter"` - `"ctrl+/"` ``` -------------------------------- ### Create Hotkey with Symbol Key Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Code.md Demonstrates creating a hotkey using a symbol key like Slash. The parse method can be used with a generic type annotation to specify HotKey. ```rust let slash_key = Code::Slash; let hotkey = "ctrl+/".parse::()?; ``` -------------------------------- ### Tauri Global Hotkey File Structure Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Overview of the directory and file layout for the Tauri Global Hotkey plugin. ```text output/ ├── README.md (this file) ├── API-SUMMARY.md ├── types.md ├── errors.md ├── configuration.md └── api-reference/ ├── GlobalHotKeyManager.md ├── HotKey.md ├── GlobalHotKeyEvent.md ├── Modifiers.md └── Code.md ``` -------------------------------- ### HotKey Serde Implementation (Optional) Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Details the Serialize and Deserialize implementations for HotKey when the 'serde' feature is enabled, allowing hotkeys to be represented as strings in formats like JSON. ```APIDOC ## Serde (optional feature) When the `serde` feature is enabled, `HotKey` implements `Serialize` and `Deserialize`, representing hotkeys as strings in JSON or other formats. ``` -------------------------------- ### Global Hotkey with Tao GUI Framework Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/configuration.md Integrates global hotkey registration and event handling within a Tao-based GUI application. It uses an event loop and a receiver to detect hotkey presses. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}, GlobalHotKeyEvent, HotKeyState}; use tao::event_loop::{ControlFlow, EventLoopBuilder}; fn main() { let event_loop = EventLoopBuilder::new().build(); let manager = GlobalHotKeyManager::new().unwrap(); let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); manager.register(hotkey).unwrap(); let receiver = GlobalHotKeyEvent::receiver(); event_loop.run(move |_event, _, control_flow| { *control_flow = ControlFlow::Poll; if let Ok(event) = receiver.try_recv() { if event.id() == hotkey.id() && event.state() == HotKeyState::Pressed { println!("Hotkey triggered!"); } } }); } ``` -------------------------------- ### Register Multiple Hotkeys Using String Configuration Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Enables registering multiple hotkeys by parsing them from string representations. This approach is convenient for configuration files or command-line arguments. Ensure proper error handling for parsing failures. ```rust let hotkey_strings = vec!["ctrl+d", "alt+e", "shift+f"]; let hotkeys: Result, _> = hotkey_strings .iter() .map(|s| s.parse::()) .collect()?; manager.register_all(&hotkeys)?; ``` -------------------------------- ### Create Hotkey with Function Key Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Code.md Demonstrates creating a hotkey using a function key like F12. The parse method can be used with a generic type annotation to specify HotKey. ```rust let f12 = Code::F12; let hotkey = "shift+F5".parse::()?; ``` -------------------------------- ### HotKey Constructor - new Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Creates a new HotKey instance. Modifiers are optional, and META is converted to SUPER for cross-platform compatibility. The ID is automatically calculated. ```rust pub fn new(mods: Option, key: Code) -> Self ``` -------------------------------- ### into_string() Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Consumes the hotkey and converts it to a string representation. Modifiers appear in order (shift, control, alt, super) followed by the key name, with `+` separators. ```APIDOC ## into_string() ### Description Consumes the hotkey and converts it to a string representation. Modifiers appear in order (shift, control, alt, super) followed by the key name, with `+` separators. ### Returns `String` - The string representation of the hotkey. ### Example ```rust let hotkey = HotKey::new(Some(Modifiers::SHIFT | Modifiers::CONTROL), Code::KeyD); assert_eq!(hotkey.into_string(), "shift+control+KeyD"); ``` ``` -------------------------------- ### Create Hotkey with Numpad Key Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Code.md Demonstrates creating a hotkey using a numpad key like NumpadAdd. The parse method can be used with a generic type annotation to specify HotKey. ```rust let numpad_5 = Code::Numpad5; let hotkey = "shift+NumpadAdd".parse::()?; ``` -------------------------------- ### Display HotKey Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Implement Display for convenient printing of HotKey instances. ```rust let hotkey = HotKey::new(Some(Modifiers::ALT), Code::KeyE); println!("{}", hotkey); // Output: alt+KeyE ``` -------------------------------- ### HotKey Fallible Conversion from String Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Illustrates fallible conversions from string slices and owned strings into HotKey instances. ```APIDOC ## TryFrom<&str> and TryFrom Fallible conversions from string slices and owned strings. ```rust let hotkey = HotKey::try_from("control+KeyD")?; let hotkey = HotKey::try_from("control+KeyD".to_string())?; ``` ``` -------------------------------- ### Registering a Global HotKey Source: https://github.com/tauri-apps/global-hotkey/blob/dev/README.md Initializes the hotkey manager and registers a specific key combination. Ensure the manager is created on the same thread as the event loop. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}}; // initialize the hotkeys manager let manager = GlobalHotKeyManager::new().unwrap(); // construct the hotkey let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); // register it manager.register(hotkey); ``` -------------------------------- ### Create a Hotkey Directly Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Instantiate a HotKey object using its modifiers and key code. This is useful for programmatic hotkey creation. ```rust // Direct creation let hotkey = HotKey::new(Some(Modifiers::CONTROL), Code::KeyD); ``` -------------------------------- ### Integrate Hotkey Events with Tao GUI Framework Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md This pattern shows how to integrate hotkey events into a Tao-based GUI application. It uses the EventLoop to manage events and checks for specific hotkey releases. Requires tao crate. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}, GlobalHotKeyEvent, HotKeyState}; use tao::event_loop::{ControlFlow, EventLoopBuilder}; let event_loop = EventLoopBuilder::new().build(); let manager = GlobalHotKeyManager::new()?; let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); manager.register(hotkey)?; let receiver = GlobalHotKeyEvent::receiver(); event_loop.run(move |_event, _, control_flow| { *control_flow = ControlFlow::Poll; if let Ok(event) = receiver.try_recv() { if event.id() == hotkey.id() && event.state() == HotKeyState::Released { println!("Hotkey released!"); } } }); ``` -------------------------------- ### HotKey Parsing from String Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Shows how to parse a HotKey from a string using the FromStr trait or the parse() method. ```APIDOC ## FromStr `HotKey` can be parsed from a string using `FromStr` or `parse()`. ```rust let hotkey: HotKey = "shift+alt+KeyQ".parse()?; ``` ``` -------------------------------- ### Dynamically Switch Between Handler and Channel Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/configuration.md Demonstrates how to dynamically switch between using a custom event handler and the default channel delivery. This allows for flexible event routing based on application state. ```rust use global_hotkey::GlobalHotKeyEvent; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; let use_handler = Arc::new(AtomicBool::new(false)); let use_handler_clone = use_handler.clone(); // Set up custom handler GlobalHotKeyEvent::set_event_handler(Some(move |event| { if use_handler_clone.load(Ordering::Relaxed) { println!("Handler: {:?}", event); } })); // Later, switch modes use_handler.store(true, Ordering::Relaxed); ``` -------------------------------- ### TryFrom HotKey from Owned String Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Attempt to convert an owned String into a HotKey instance. This conversion can fail. ```rust let hotkey = HotKey::try_from("control+KeyD".to_string())?; ``` -------------------------------- ### Async Global Hotkey Integration Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/configuration.md Shows how to integrate global hotkeys into an asynchronous Rust application using async-std. It spawns a blocking thread to handle hotkey events while the main thread continues async operations. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}, GlobalHotKeyEvent}; use std::thread; #[async_std::main] async fn main() -> Result<()> { let manager = GlobalHotKeyManager::new()?; let hotkey = HotKey::new(Some(Modifiers::CONTROL), Code::KeyD); manager.register(hotkey)?; let receiver = GlobalHotKeyEvent::receiver(); // Spawn blocking thread for event receiving thread::spawn(move || { while let Ok(event) = receiver.recv() { println!("Event: {:?}", event); } }); // Continue async work loop { async_std::task::sleep(std::time::Duration::from_secs(1)).await; } } ``` -------------------------------- ### Create Hotkey with Digit Key Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Code.md Demonstrates creating a hotkey using a digit key. String parsing can use single digits which are equivalent to their Code enum variants. ```rust let code = Code::Digit5; let hotkey = "ctrl+5".parse()?; // Equivalent to ctrl+Digit5 ``` -------------------------------- ### Match on Specific Errors Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/errors.md Demonstrates how to handle specific errors like `AlreadyRegistered` and `FailedToRegister` when registering a hotkey. This pattern is useful for providing user-friendly feedback or alternative actions. ```rust use global_hotkey::{GlobalHotKeyManager, hotkey::{HotKey, Modifiers, Code}, Error}; let manager = GlobalHotKeyManager::new()?; let hotkey = HotKey::new(Some(Modifiers::CONTROL), Code::KeyD); match manager.register(hotkey) { Ok(()) => println!("Registered successfully"), Err(Error::AlreadyRegistered(hk)) => { println!("Already registered: {:?}", hk); manager.unregister(hk)?; manager.register(hotkey)?; } Err(Error::FailedToRegister(reason)) => { eprintln!("Registration failed: {}", reason); } Err(e) => eprintln!("Other error: {}", e), } ``` -------------------------------- ### GlobalHotKeyManager Methods Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/INDEX.md Methods for managing hotkeys: creating a new manager, registering a hotkey, and unregistering a hotkey. Registration can result in an error if the hotkey is already registered. ```rust GlobalHotKeyManager::new() -> Result ``` ```rust manager.register(HotKey) -> Result<()> ``` ```rust manager.unregister(HotKey) -> Result<()> ``` -------------------------------- ### Register a Hotkey Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Register a hotkey with the GlobalHotKeyManager. Ensure the hotkey is valid before registering. ```rust manager.register(hotkey)? ``` -------------------------------- ### GlobalHotKeyManager Methods Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Provides methods for creating a GlobalHotKeyManager and registering or unregistering hotkeys. ```APIDOC ## GlobalHotKeyManager::new() ### Description Creates a new instance of the GlobalHotKeyManager. ### Method `GlobalHotKeyManager::new()` ### Returns `Result` - A Result containing the new manager or an error. ## manager.register(hotkey) ### Description Registers a single hotkey with the system. ### Method `manager.register(hotkey)` ### Parameters - **hotkey** (`HotKey`) - The hotkey to register. ### Returns `Result<()>` - An empty Result on success, or an error if registration fails. ## manager.unregister(hotkey) ### Description Unregisters a single hotkey from the system. ### Method `manager.unregister(hotkey)` ### Parameters - **hotkey** (`HotKey`) - The hotkey to unregister. ### Returns `Result<()>` - An empty Result on success, or an error if unregistration fails. ## manager.register_all(hotkeys) ### Description Registers multiple hotkeys with the system. ### Method `manager.register_all(hotkeys)` ### Parameters - **hotkeys** (`Vec`) - A vector of hotkeys to register. ### Returns `Result<()>` - An empty Result on success, or an error if any registration fails. ## manager.unregister_all(hotkeys) ### Description Unregisters multiple hotkeys from the system. ### Method `manager.unregister_all(hotkeys)` ### Parameters - **hotkeys** (`Vec`) - A vector of hotkeys to unregister. ### Returns `Result<()>` - An empty Result on success, or an error if any unregistration fails. ``` -------------------------------- ### TryFrom HotKey from String Slice Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Attempt to convert a string slice into a HotKey instance. This conversion can fail. ```rust let hotkey = HotKey::try_from("control+KeyD")?; ``` -------------------------------- ### GlobalHotKeyEvent Methods Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Provides methods for handling global hotkey events. ```APIDOC ## GlobalHotKeyEvent::receiver() ### Description Retrieves a static receiver for the global hotkey event channel. ### Method `GlobalHotKeyEvent::receiver()` ### Returns `&'static Receiver<...>` - A reference to the event channel receiver. ## GlobalHotKeyEvent::set_event_handler(f) ### Description Sets a custom handler function for global hotkey events. ### Method `GlobalHotKeyEvent::set_event_handler(f)` ### Parameters - **f** (`FnMut(GlobalHotKeyEvent)`) - The closure or function to be called when a hotkey event occurs. ### Returns `()` ``` -------------------------------- ### Enable Tracing Feature Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Add this to your Cargo.toml to enable logging support via the tracing crate. ```toml [dependencies] global-hotkey = { version = "0.8", features = ["tracing"] } ``` -------------------------------- ### Receive Hotkey Events Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/INDEX.md Illustrates how to obtain the event receiver for hotkeys and check for incoming events using `try_recv`. This is used to react when a registered hotkey is activated. ```rust let rx = GlobalHotKeyEvent::receiver(); if let Ok(event) = rx.try_recv() { println!("Event {}: {:?}", event.id(), event.state()); } ``` -------------------------------- ### Supported Key Names Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/HotKey.md Lists the common key names supported by the library, categorized for clarity. ```APIDOC ### Supported Key Names The library supports all key codes from the `keyboard_types` crate. Common names include: **Letters**: `KeyA` through `KeyZ` (or just `A`-`Z`) **Digits**: `Digit0` through `Digit9` (or just `0`-`9`) **Navigation**: `Home`, `End`, `PageUp`, `PageDown`, `ArrowUp`, `ArrowDown`, `ArrowLeft`, `ArrowRight` **Function keys**: `F1` through `F24` **Special**: `Enter`, `Space`, `Tab`, `Escape`, `Backspace`, `Delete`, `Insert`, `CapsLock`, `NumLock` **Symbols**: `Comma`, `Period`, `Semicolon`, `Quote`, `Backslash`, `Slash`, `BracketLeft`, `BracketRight`, `Backquote`, etc. **Keypad**: `Numpad0` through `Numpad9`, `NumpadAdd`, `NumpadSubtract`, `NumpadMultiply`, `NumpadDivide`, `NumpadDecimal`, `NumpadEnter`, `NumpadEqual` **Media**: `MediaPlay`, `MediaPause`, `MediaPlayPause`, `MediaStop`, `MediaTrackNext`, `MediaTrackPrevious`, `AudioVolumeUp`, `AudioVolumeDown`, `AudioVolumeMute` ``` -------------------------------- ### Create Hotkey with Letter Key Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Code.md Demonstrates creating a hotkey using a letter key. String parsing can use single letters which are equivalent to their Code enum variants. ```rust use global_hotkey::hotkey::Code; let code = Code::KeyA; let hotkey = "shift+A".parse()?; // Equivalent to shift+KeyA ``` -------------------------------- ### Parse Hotkey from String Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/INDEX.md Shows how to parse a hotkey directly from a string representation, combining modifiers and key names. The parsed hotkey can then be registered with the manager. ```rust let hk: HotKey = "shift+alt+KeyQ".parse()?; mgr.register(hk)?; ``` -------------------------------- ### Create a Hotkey Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Define a new hotkey by specifying optional modifiers and a key code. Modifiers like SHIFT and keys like KeyD are common. ```rust HotKey::new(Some(Modifiers::SHIFT), Code::KeyD) ``` -------------------------------- ### Register Hotkey Error Handling Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Shows how to handle registration errors, specifically when a hotkey is already registered. It includes unregistering and re-registering the hotkey. ```rust match manager.register(hotkey) { Ok(()) => println!("Registered"), Err(global_hotkey::Error::AlreadyRegistered(hk)) => { println!("Already registered: {:?}", hk); manager.unregister(hk)?; manager.register(hotkey)?; } Err(e) => eprintln!("Error: {}", e), } ``` -------------------------------- ### HotKey API Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/MANIFEST.md Documentation for the `HotKey` type, representing a global hotkey combination. ```APIDOC ## HotKey ### Description Represents a global hotkey, typically composed of modifiers and a key code. ### Constructors - `from_string(s: &str)`: Creates a `HotKey` from a string representation (e.g., "Ctrl+Shift+A"). - `new(modifiers: Modifiers, code: Code)`: Creates a `HotKey` from explicit modifiers and key code. ### Methods - `modifiers()`: Returns the `Modifiers` associated with the hotkey. - `code()`: Returns the `Code` associated with the hotkey. ### Parameters - `s` (string slice): String representation of the hotkey. - `modifiers` (Modifiers): Bitflags representing modifier keys (e.g., Ctrl, Shift, Alt). - `code` (Code): Enum variant representing the main key. ### Return Documentation - `from_string` returns `Result`. - `modifiers` and `code` return their respective types. ### Error Conditions - `from_string` can return an error if the input string is not a valid hotkey format. ``` -------------------------------- ### Display Hotkey as String Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/API-SUMMARY.md Convert a HotKey object into its string representation. Useful for logging or displaying the hotkey. ```rust println!("{}", hotkey); // Output: control+alt+KeyQ ``` -------------------------------- ### Create Hotkey Dynamically Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Modifiers.md Dynamically construct a HotKey by conditionally adding the Shift modifier. Requires importing HotKey, Modifiers, and Code. ```rust use global_hotkey::hotkey::{HotKey, Modifiers, Code}; fn create_hotkey(use_shift: bool, key: Code) -> HotKey { let mut mods = Modifiers::CONTROL; if use_shift { mods.insert(Modifiers::SHIFT); } HotKey::new(Some(mods), key) } let hotkey = create_hotkey(true, Code::KeyD); // Creates Ctrl+Shift+D ``` -------------------------------- ### GlobalHotKeyManager API Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/MANIFEST.md Documentation for the `GlobalHotKeyManager` type, which provides methods for managing global hotkeys. ```APIDOC ## GlobalHotKeyManager ### Description Provides methods for registering, unregistering, and managing global hotkeys. ### Methods - `new()`: Constructor for `GlobalHotKeyManager`. - `register(hotkey: HotKey, handler: Box)`: Registers a new hotkey with a given handler. - `unregister(hotkey: HotKey)`: Unregisters a specific hotkey. - `unregister_all()`: Unregisters all registered hotkeys. ### Parameters - `hotkey` (HotKey): The hotkey to register or unregister. - `handler` (Box): A closure to be executed when the hotkey is pressed. ### Return Documentation - Methods typically return `Result<(), Error>` indicating success or failure. ### Error Conditions - Errors can occur during hotkey registration or unregistration due to platform limitations or invalid configurations. ``` -------------------------------- ### Register a Hotkey Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/README.md Register a single hotkey with the manager. Ensure the `HotKey` object is correctly constructed. ```rust manager.register(hotkey)?; ``` -------------------------------- ### Cross-Platform Save Hotkey Source: https://github.com/tauri-apps/global-hotkey/blob/dev/_autodocs/api-reference/Modifiers.md Creates a save hotkey that works across platforms (Cmd+Shift+S on macOS, Ctrl+Shift+S on Windows/Linux). ```rust let save = HotKey::new( Some(CMD_OR_CTRL | Modifiers::SHIFT), Code::KeyS ); ```