跳到内容
Tauri

@tauri-apps/plugin-global-shortcut

注册全局快捷键。

接口

ShortcutEvent

属性

属性类型定义于
idnumberSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L15
shortcutstringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L14
state"Released" | "Pressed"Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L16

类型别名

ShortcutHandler()

type ShortcutHandler: (event) => void;

参数

参数类型
eventShortcutEvent

返回值

void

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

函数

isRegistered()

function isRegistered(shortcut): Promise<boolean>

确定给定的快捷键是否已由此应用程序注册。

如果快捷键已由另一个应用程序注册,它仍将返回 false

参数

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

返回值

Promise<boolean>

示例

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

始于

2.0.0

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


register()

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

注册一个全局快捷键或快捷键列表。

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

如果快捷键已被另一个应用程序占用,则不会触发处理程序。请确保快捷键尽可能唯一,同时仍考虑用户体验。

参数

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

返回值

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

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


unregister()

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

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


unregisterAll()

function unregisterAll(): Promise<void>

注销所有全局快捷键。

返回值

Promise<void>

示例

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

始于

2.0.0

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


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