Skip to content
Tauri
Releases

globalShortcut

Register global shortcuts.

This package is also accessible with window.__TAURI__.globalShortcut when build.withGlobalTauri in tauri.conf.json is set to true.

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.

Type Aliases

ShortcutHandler

ShortcutHandler: (shortcut) => void

Parameters

ParameterType
shortcutstring

Returns

void

Source: 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');

Since

1.0.0

Parameters

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

Returns

Promise< boolean >

Source: globalShortcut.ts:101


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');
});

Since

1.0.0

Parameters

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

Returns

Promise< void >

Source: globalShortcut.ts:46


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`);
});

Since

1.0.0

Parameters

ParameterTypeDescription
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 >

Source: globalShortcut.ts:75


unregister()

unregister(shortcut): Promise< void >

Unregister a global shortcut.

Example

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

Since

1.0.0

Parameters

ParameterTypeDescription
shortcutstringshortcut definition, modifiers and key separated by ”+” e.g. CmdOrControl+Q

Returns

Promise< void >

Source: globalShortcut.ts:123


unregisterAll()

unregisterAll(): Promise< void >

Unregisters all shortcuts registered by the application.

Example

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

Since

1.0.0

Returns

Promise< void >

Source: globalShortcut.ts:143


© 2024 Tauri Contributors. CC-BY / MIT