Skip to content
Tauri 中文网

全球快捷方式

注册全局快捷方式。

¥Register global shortcuts.

支持的平台

¥Supported Platforms

This plugin requires a Rust version of at least 1.77.2

Platform Level Notes
windows
linux
macos
android
ios

设置

¥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

使用

¥Usage

global-shortcut 插件在 JavaScript 和 Rust 中均可用。

¥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');
});

权限

¥Permissions

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

¥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/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"
]
}

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.


Tauri 中文网 - 粤ICP备13048890号