Skip to content
Tauri

@tauri-apps/plugin-global-shortcut

Register global shortcuts.

Interfaces

ShortcutEvent

Properties

PropertyType
idnumber
shortcutstring
state"Released" | "Pressed"

Type Aliases

ShortcutHandler()

type ShortcutHandler: (event) => void;

Parameters

ParameterType
eventShortcutEvent

Returns

void

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L19

Functions

isRegistered()

function isRegistered(shortcut): Promise<boolean>

Determines whether the given shortcut is registered by this application or not.

If the shortcut is registered by another application, it will still return false.

Parameters

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

Returns

Promise<boolean>

Example

import { isRegistered } from '@tauri-apps/plugin-global-shortcut';
const isRegistered = await isRegistered('CommandOrControl+P');

Since

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L94


register()

function register(shortcut, handler): Promise<void>

Register a global shortcut.

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>

Example

import { register } from '@tauri-apps/plugin-global-shortcut';
await register('CommandOrControl+Shift+C', (event) => {
if (event.state === "Pressed") {
console.log('Shortcut triggered');
}
});

Since

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L38


registerAll()

function registerAll(shortcuts, handler): Promise<void>

Register a collection of global shortcuts.

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>

Example

import { registerAll } from '@tauri-apps/plugin-global-shortcut';
await registerAll(['CommandOrControl+Shift+C', 'Ctrl+Alt+F12'], (event) => {
console.log(`Shortcut ${event.shortcut} ${event.state}`);
});

Since

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L66


unregister()

function unregister(shortcut): Promise<void>

Unregister a global shortcut.

Parameters

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

Returns

Promise<void>

Example

import { unregister } from '@tauri-apps/plugin-global-shortcut';
await unregister('CmdOrControl+Space');

Since

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L112


unregisterAll()

function unregisterAll(): Promise<void>

Unregisters all shortcuts registered by the application.

Returns

Promise<void>

Example

import { unregisterAll } from '@tauri-apps/plugin-global-shortcut';
await unregisterAll();

Since

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L128


© 2024 Tauri Contributors. CC-BY / MIT