跳到内容
Tauri

@tauri-apps/plugin-global-shortcut

注册全局快捷键。

属性类型定义于
id数字来源https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L15
快捷键字符串来源https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L14
状态"Released" | "Pressed"来源https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L16

type ShortcutHandler: (event) => void;
参数类型
事件快捷键事件

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

function isRegistered(shortcut): Promise<boolean>

判断此应用程序是否已注册给定快捷键。

如果快捷键已被其他应用程序注册,它仍将返回 false

参数类型描述
快捷键字符串快捷键定义,修饰符和按键用“+”分隔,例如 CmdOrControl+Q

Promise<boolean>

import { isRegistered } from '@tauri-apps/plugin-global-shortcut';
const isRegistered = await isRegistered('CommandOrControl+P');

2.0.0

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


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

注册一个或多个全局快捷键。

当用户按下任何注册的快捷键时,将调用处理程序。

如果快捷键已被其他应用程序占用,则处理程序将不会被触发。请确保快捷键尽可能独特,同时考虑到用户体验。

参数类型描述
快捷键string | string[]-
处理程序快捷键处理器快捷键处理回调 - 将触发的快捷键作为参数

Promise<void>

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`);
});

2.0.0

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


function unregister(shortcuts): Promise<void>

注销一个或多个全局快捷键。

参数类型
快捷键string | string[]

Promise<void>

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']);

2.0.0

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


function unregisterAll(): Promise<void>

注销所有全局快捷键。

Promise<void>

import { unregisterAll } from '@tauri-apps/plugin-global-shortcut';
await unregisterAll();

2.0.0

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


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