跳到主要內容
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

參數

參數類型描述
shortcutstring快捷鍵定義,修飾符和按鍵以「+」分隔,例如 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>

註冊全域快捷鍵或快捷鍵列表。

當使用者按下任何已註冊的快捷鍵時,將呼叫處理常式。

如果快捷鍵已被另一個應用程式佔用,則不會觸發處理常式。請確保快捷鍵盡可能獨特,同時仍考慮使用者體驗。

參數

參數類型描述
shortcutsstring | string[]-
handlerShortcutHandler快捷鍵處理常式回呼 - 接收觸發的快捷鍵作為參數

回傳

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>

取消註冊全域快捷鍵或快捷鍵列表。

參數

參數類型
shortcutsstring | 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 Contributors. CC-BY / MIT