▸ Agent Skills
3 min read

Global Shortcut

GitHubnpmcrates.io

API Reference:

Register global shortcuts.

Supported Platforms

This plugin requires a Rust version of at least 1.77.2

[TABLE]

Setup

Install the global-shortcut plugin to get started.

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

npm run tauri add global-shortcut
yarn run tauri add global-shortcut
pnpm tauri add global-shortcut
deno task tauri add global-shortcut
bun tauri add global-shortcut
cargo tauri add global-shortcut
  1. Run the following command in the src-tauri folder to add the plugin to the project’s dependencies in Cargo.toml:

    cargo add tauri-plugin-global-shortcut --target 'cfg(any(target_os = "macos", windows, target_os = "linux"))'
  2. Modify lib.rs to initialize the plugin:

    pub fn run() {    tauri::Builder::default()        .setup(|app| {            #[cfg(desktop)]            app.handle().plugin(tauri_plugin_global_shortcut::Builder::new().build());            Ok(())        })        .run(tauri::generate_context!())        .expect("error while running tauri application");}

    src-tauri/src/lib.rs

  3. Install the JavaScript Guest bindings using your preferred JavaScript package manager:

    npm install @tauri-apps/plugin-global-shortcut
    yarn add @tauri-apps/plugin-global-shortcut
    pnpm add @tauri-apps/plugin-global-shortcut
    deno add npm:@tauri-apps/plugin-global-shortcut
    bun add @tauri-apps/plugin-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__.globalShortcut;
await register('CommandOrControl+Shift+C', () => {  console.log('Shortcut triggered');});
pub fn run() {    tauri::Builder::default()        .setup(|app| {            #[cfg(desktop)]            {                use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};
                let ctrl_n_shortcut = Shortcut::new(Some(Modifiers::CONTROL), Code::KeyN);                app.handle().plugin(                    tauri_plugin_global_shortcut::Builder::new().with_handler(move |_app, shortcut, event| {                        println!("{:?}", shortcut);                        if shortcut == &ctrl_n_shortcut {                            match event.state() {                              ShortcutState::Pressed => {                                println!("Ctrl-N Pressed!");                              }                              ShortcutState::Released => {                                println!("Ctrl-N Released!");                              }                            }                        }                    })                    .build(),                )?;
                app.global_shortcut().register(ctrl_n_shortcut)?;            }            Ok(())        })        .run(tauri::generate_context!())        .expect("error while running tauri application");}

src-tauri/src/lib.rs

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.

{  "$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"  ]}

src-tauri/capabilities/default.json

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

IdentifierDescription
global-shortcut:allow-is-registeredEnables the is_registered command without any pre-configured scope.
global-shortcut:deny-is-registeredDenies the is_registered command without any pre-configured scope.
global-shortcut:allow-registerEnables the register command without any pre-configured scope.
global-shortcut:deny-registerDenies the register command without any pre-configured scope.
global-shortcut:allow-register-allEnables the register_all command without any pre-configured scope.
global-shortcut:deny-register-allDenies the register_all command without any pre-configured scope.
global-shortcut:allow-unregisterEnables the unregister command without any pre-configured scope.
global-shortcut:deny-unregisterDenies the unregister command without any pre-configured scope.
global-shortcut:allow-unregister-allEnables the unregister_all command without any pre-configured scope.
global-shortcut:deny-unregister-allDenies the unregister_all command without any pre-configured scope.

Support on Open CollectiveSponsor on GitHub

© 2026 Tauri Contributors. CC-BY / MIT


Last updated Oct 08, 2026