globalShortcut
@tauri-apps/api / globalShortcut
Module: globalShortcut
Register global shortcuts.
This package is also accessible with window.__TAURI__.globalShortcut
when tauri.conf.json > build > withGlobalTauri
is set to true.
The APIs must be allowlisted on 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.
Type Aliases​
ShortcutHandler​
Ƭ ShortcutHandler: (shortcut
: string
) => void
Type declaration​
â–¸ (shortcut
): void
Parameters​
Name | Type |
---|---|
shortcut | string |
Returns​
void
Defined in​
Functions​
isRegistered​
â–¸ isRegistered(shortcut
): Promise
<boolean
>
Determines whether the given shortcut is registered by this application or not.
example
import { isRegistered } from '@tauri-apps/api/globalShortcut';
const isRegistered = await isRegistered('CommandOrControl+P');
Parameters​
Name | Type | Description |
---|---|---|
shortcut | string | Array of shortcut definitions, modifiers and key separated by "+" e.g. CmdOrControl+Q |
Returns​
Promise
<boolean
>
A promise resolving to the state.
Defined in​
register​
â–¸ register(shortcut
, handler
): Promise
<void
>
Register a global shortcut.
example
import { register } from '@tauri-apps/api/globalShortcut';
await register('CommandOrControl+Shift+C', () => {
console.log('Shortcut triggered');
});
Parameters​
Name | Type | Description |
---|---|---|
shortcut | string | Shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q |
handler | ShortcutHandler | Shortcut handler callback - takes the triggered shortcut as argument |
Returns​
Promise
<void
>
Defined in​
registerAll​
â–¸ registerAll(shortcuts
, handler
): Promise
<void
>
Register a collection of global shortcuts.
example
import { registerAll } from '@tauri-apps/api/globalShortcut';
await registerAll(['CommandOrControl+Shift+C', 'Ctrl+Alt+F12'], (shortcut) => {
console.log(`Shortcut ${shortcut} triggered`);
});
Parameters​
Name | Type | Description |
---|---|---|
shortcuts | string [] | Array of shortcut definitions, modifiers and key separated by "+" e.g. CmdOrControl+Q |
handler | ShortcutHandler | Shortcut handler callback - takes the triggered shortcut as argument |
Returns​
Promise
<void
>
Defined in​
unregister​
â–¸ unregister(shortcut
): Promise
<void
>
Unregister a global shortcut.
example
import { unregister } from '@tauri-apps/api/globalShortcut';
await unregister('CmdOrControl+Space');
Parameters​
Name | Type | Description |
---|---|---|
shortcut | string | shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q |
Returns​
Promise
<void
>
Defined in​
unregisterAll​
â–¸ unregisterAll(): Promise
<void
>
Unregisters all shortcuts registered by the application.
example
import { unregisterAll } from '@tauri-apps/api/globalShortcut';
await unregisterAll();
Returns​
Promise
<void
>