Expand description
Register global shortcuts.
§Differences to the JavaScript API
§registerAll
let shortcuts = ["CommandOrControl+Shift+C", "Ctrl+Alt+F12"];
let streams = futures::future::try_join_all(shortcuts.map(|s| async move {
let stream = global_shortcut::register(s).await?;
anyhow::Ok(stream.map(move |_| s))
}))
.await?;
let mut events = futures::stream::select_all(streams);
while let Some(shortcut) = events.next().await {
log::debug!("Shortcut {} triggered", shortcut)
}
The APIs must be added to tauri.allowlist.globalShortcut in tauri.conf.json:
{
"tauri": {
"allowlist": {
"globalShortcut": {
"all": true // enable all global shortcut APIs
}
}
}
}
It is recommended to allowlist only the APIs you use for optimal bundle size and security.
Functions§
- Determines whether the given shortcut is registered by this application or not.
- Register a global shortcut.