Skip to content
Tauri

@tauri-apps/plugin-global-shortcut

Register global shortcuts.

Interfaces

ShortcutEvent

Properties

PropertyTypeDefined in
idnumberSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L15
shortcutstringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L14
state"Released" | "Pressed"Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L16

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#L117


register()

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

Register a global shortcut or a list of shortcuts.

The handler is called when any of the registered shortcuts are pressed by the user.

If the shortcut is already taken by another application, the handler will not be triggered. Make sure the shortcut is as unique as possible while still taking user experience into consideration.

Parameters

ParameterTypeDescription
shortcutsstring | string[]-
handlerShortcutHandlerShortcut handler callback - takes the triggered shortcut as argument

Returns

Promise<void>

Example

import { register } from '@tauri-apps/plugin-global-shortcut';
// register a single hotkey
await register('CommandOrControl+Shift+C', (event) => {
if (event.state === "Pressed") {
console.log('Shortcut triggered');
}
});
// or register multiple hotkeys at once
await register(['CommandOrControl+Shift+C', 'Alt+A'], (event) => {
console.log(`Shortcut ${event.shortcut} triggered`);
});

Since

2.0.0

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


unregister()

function unregister(shortcuts): Promise<void>

Unregister a global shortcut or a list of shortcuts.

Parameters

ParameterType
shortcutsstring | string[]

Returns

Promise<void>

Example

import { unregister } from '@tauri-apps/plugin-global-shortcut';
// unregister a single hotkey
await unregister('CmdOrControl+Space');
// or unregister multiple hotkeys at the same time
await unregister(['CmdOrControl+Space', 'Alt+A']);

Since

2.0.0

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


unregisterAll()

function unregisterAll(): Promise<void>

Unregister all global shortcuts.

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#L98


© 2024 Tauri Contributors. CC-BY / MIT