Skip to main content

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​
NameType
shortcutstring
Returns​

void

Defined in​

globalShortcut.ts:29

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​

NameTypeDescription
shortcutstringArray of shortcut definitions, modifiers and key separated by "+" e.g. CmdOrControl+Q

Returns​

Promise<boolean>

A promise resolving to the state.

Defined in​

globalShortcut.ts:98


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​

NameTypeDescription
shortcutstringShortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q
handlerShortcutHandlerShortcut handler callback - takes the triggered shortcut as argument

Returns​

Promise<void>

Defined in​

globalShortcut.ts:45


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​

NameTypeDescription
shortcutsstring[]Array of shortcut definitions, modifiers and key separated by "+" e.g. CmdOrControl+Q
handlerShortcutHandlerShortcut handler callback - takes the triggered shortcut as argument

Returns​

Promise<void>

Defined in​

globalShortcut.ts:73


unregister​

â–¸ unregister(shortcut): Promise<void>

Unregister a global shortcut.

example

import { unregister } from '@tauri-apps/api/globalShortcut';
await unregister('CmdOrControl+Space');

Parameters​

NameTypeDescription
shortcutstringshortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q

Returns​

Promise<void>

Defined in​

globalShortcut.ts:119


unregisterAll​

â–¸ unregisterAll(): Promise<void>

Unregisters all shortcuts registered by the application.

example

import { unregisterAll } from '@tauri-apps/api/globalShortcut';
await unregisterAll();

Returns​

Promise<void>

Defined in​

globalShortcut.ts:139