グローバルショートカット
アプリケーションがフォーカスされていないときでもグローバルキーボードショートカットを登録します。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | | |
| ios | |
グローバルショートカットプラグインをインストールして開始します。
プロジェクトのパッケージマネージャーを使用して依存関係を追加します。
npm run tauri add global-shortcutyarn run tauri add global-shortcutpnpm tauri add global-shortcutdeno task tauri add global-shortcutbun tauri add global-shortcutcargo tauri add global-shortcut-
src-tauriフォルダで次のコマンドを実行して、Cargo.tomlのプロジェクトの依存関係にプラグインを追加します。cargo add tauri-plugin-global-shortcut --target 'cfg(any(target_os = "macos", windows, target_os = "linux"))' -
lib.rsを変更してプラグインを初期化します。src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_global_shortcut::Builder::new().build()).run(tauri::generate_context!()).expect("error while running tauri application");} -
お好みの JavaScript パッケージマネージャーを使用して、JavaScript ゲストバインディングをインストールします。
npm install @tauri-apps/plugin-global-shortcutyarn add @tauri-apps/plugin-global-shortcutpnpm add @tauri-apps/plugin-global-shortcutdeno add npm:@tauri-apps/plugin-global-shortcutbun add @tauri-apps/plugin-global-shortcut
グローバルショートカットプラグインは、JavaScript と Rust の両方で使用できます。
import { register } from '@tauri-apps/plugin-global-shortcut';
await register('CommandOrControl+Shift+C', () => { console.log('Shortcut triggered');});use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};
fn register_shortcut(app: &mut tauri::App) { let ctrl_n_shortcut = Shortcut::new(Some(Modifiers::CONTROL), Code::KeyN); app.handle().plugin( tauri_plugin_global_shortcut::Builder::new().with_handler(move |app, shortcut, event| { println!("{:?}", shortcut); if shortcut == &ctrl_n_shortcut { match event.state() { ShortcutState::Pressed => { println!("Ctrl-N Pressed!"); } ShortcutState::Released => { println!("Ctrl-N Released!"); } } } }) .build(), )?;
app.global_shortcut().register(ctrl_n_shortcut)?;}デフォルトでは、すべての潜在的に危険なプラグインコマンドとスコープはブロックされており、アクセスできません。これらを有効にするには、capabilities 設定の権限を変更する必要があります。
詳細については、機能の概要 と、プラグイン権限を使用するための ステップバイステップガイド を参照してください。
{ "permissions": [ ..., "global-shortcut:allow-register", ]}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 |
|---|---|
|
|
Enables the is_registered command without any pre-configured scope. |
|
|
Denies the is_registered command without any pre-configured scope. |
|
|
Enables the register command without any pre-configured scope. |
|
|
Denies the register command without any pre-configured scope. |
|
|
Enables the register_all command without any pre-configured scope. |
|
|
Denies the register_all command without any pre-configured scope. |
|
|
Enables the unregister command without any pre-configured scope. |
|
|
Denies the unregister command without any pre-configured scope. |
|
|
Enables the unregister_all command without any pre-configured scope. |
|
|
Denies the unregister_all command without any pre-configured scope. |
© 2025 Tauri Contributors. CC-BY / MIT