跳到内容
Tauri

全局快捷键

注册全局快捷键。

此插件需要 Rust 版本至少为 **1.77.2**

平台 级别 备注
windows
linux
macos
android
ios

安装 global-shortcut 插件即可开始使用。

使用你的项目包管理器添加依赖项

npm run tauri add global-shortcut

global-shortcut 插件同时支持 JavaScript 和 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');
});

默认情况下,所有潜在危险的插件命令和范围都被阻止,无法访问。您必须修改 capabilities 配置中的权限才能启用这些功能。

有关更多信息,请参阅功能概述,并参阅分步指南以使用插件权限。

src-tauri/capabilities/default.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"
]
}

默认权限

默认不启用任何功能,因为我们认为快捷键本身可能具有危险性,是否注册或注销特定快捷键应由具体的应用程序决定。

权限表

标识符 描述

global-shortcut:allow-is-registered

在没有预配置作用域的情况下启用 is_registered 命令。

global-shortcut:deny-is-registered

在没有预配置作用域的情况下禁用 is_registered 命令。

global-shortcut:allow-register

在没有预配置作用域的情况下启用 register 命令。

global-shortcut:deny-register

在没有预配置作用域的情况下禁用 register 命令。

global-shortcut:allow-register-all

在没有预配置作用域的情况下启用 register_all 命令。

global-shortcut:deny-register-all

在没有预配置作用域的情况下禁用 register_all 命令。

global-shortcut:allow-unregister

在没有预配置作用域的情况下启用 unregister 命令。

global-shortcut:deny-unregister

在没有预配置作用域的情况下禁用 unregister 命令。

global-shortcut:allow-unregister-all

在没有预配置作用域的情况下启用 unregister_all 命令。

global-shortcut:deny-unregister-all

在没有预配置作用域的情况下禁用 unregister_all 命令。


© 2026 Tauri 贡献者。CC-BY / MIT