@tauri-apps/plugin-global-shortcut
註冊全域快捷鍵。
介面
ShortcutEvent
屬性
屬性 | 類型 | 定義於 |
---|---|---|
id | number | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/global-shortcut/guest-js/index.ts#L15 |
shortcut | string | Source: 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;
參數
參數 | 類型 |
---|---|
event | ShortcutEvent |
回傳
void
函式
isRegistered()
function isRegistered(shortcut): Promise<boolean>
判斷給定的快捷鍵是否已由此應用程式註冊。
如果快捷鍵是由另一個應用程式註冊的,它仍然會回傳 false
。
參數
參數 | 類型 | 描述 |
---|---|---|
shortcut | string | 快捷鍵定義,修飾符和按鍵以「+」分隔,例如 CmdOrControl+Q |
回傳
Promise
<boolean
>
範例
import { isRegistered } from '@tauri-apps/plugin-global-shortcut';const isRegistered = await isRegistered('CommandOrControl+P');
自從
2.0.0
register()
function register(shortcuts, handler): Promise<void>
註冊全域快捷鍵或快捷鍵列表。
當使用者按下任何已註冊的快捷鍵時,將呼叫處理常式。
如果快捷鍵已被另一個應用程式佔用,則不會觸發處理常式。請確保快捷鍵盡可能獨特,同時仍考慮使用者體驗。
參數
參數 | 類型 | 描述 |
---|---|---|
shortcuts | string | string [] | - |
handler | ShortcutHandler | 快捷鍵處理常式回呼 - 接收觸發的快捷鍵作為參數 |
回傳
Promise
<void
>
範例
import { register } from '@tauri-apps/plugin-global-shortcut';
// register a single hotkeyawait register('CommandOrControl+Shift+C', (event) => { if (event.state === "Pressed") { console.log('Shortcut triggered'); }});
// or register multiple hotkeys at onceawait register(['CommandOrControl+Shift+C', 'Alt+A'], (event) => { console.log(`Shortcut ${event.shortcut} triggered`);});
自從
2.0.0
unregister()
function unregister(shortcuts): Promise<void>
取消註冊全域快捷鍵或快捷鍵列表。
參數
參數 | 類型 |
---|---|
shortcuts | string | string [] |
回傳
Promise
<void
>
範例
import { unregister } from '@tauri-apps/plugin-global-shortcut';
// unregister a single hotkeyawait unregister('CmdOrControl+Space');
// or unregister multiple hotkeys at the same timeawait unregister(['CmdOrControl+Space', 'Alt+A']);
自從
2.0.0
unregisterAll()
function unregisterAll(): Promise<void>
取消註冊所有全域快捷鍵。
回傳
Promise
<void
>
範例
import { unregisterAll } from '@tauri-apps/plugin-global-shortcut';await unregisterAll();
自從
2.0.0
© 2025 Tauri Contributors. CC-BY / MIT