Skip to content
Tauri

Global Shortcut

Register global shortcuts.

Supported Platforms

  • Windows
  • Linux
  • macOS

Setup

This plugin requires a Rust version of at least 1.75

Install the global-shortcut plugin to get started.

Use your project’s package manager to add the dependency:

npm run tauri add global-shortcut

Usage

The global-shortcut plugin is available in both JavaScript and Rust.

import { register } from '@tauri-apps/plugin-global-shortcut';
// when using `"withGlobalTauri": true`, you may use
// const { register } = window.__TAURI_PLUGIN_GLOBAL_SHORTCUT__;
await register('CommandOrControl+Shift+C', () => {
console.log('Shortcut triggered');
});

Permissions

By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your capabilities configuration to enable these.

See the Capabilities Overview for more information and the step by step guide to use plugin permissions.

src-tauri/capabilities/main.json
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "main-capability",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"global-shortcut:allow-is-registered",
"global-shortcut:allow-register",
"global-shortcut:allow-unregister"
]
}

Default Permission

No features are enabled by default, as we believe the shortcuts can be inherently dangerous and it is application specific if specific shortcuts should be registered or unregistered.

Permission Table

Identifier Description

global-shortcut:allow-is-registered

Enables the is_registered command without any pre-configured scope.

global-shortcut:deny-is-registered

Denies the is_registered command without any pre-configured scope.

global-shortcut:allow-register

Enables the register command without any pre-configured scope.

global-shortcut:deny-register

Denies the register command without any pre-configured scope.

global-shortcut:allow-register-all

Enables the register_all command without any pre-configured scope.

global-shortcut:deny-register-all

Denies the register_all command without any pre-configured scope.

global-shortcut:allow-unregister

Enables the unregister command without any pre-configured scope.

global-shortcut:deny-unregister

Denies the unregister command without any pre-configured scope.

global-shortcut:allow-unregister-all

Enables the unregister_all command without any pre-configured scope.

global-shortcut:deny-unregister-all

Denies the unregister_all command without any pre-configured scope.


© 2024 Tauri Contributors. CC-BY / MIT