Menu

Post image 1
Post image 2
1 / 2
0

Global Keyboard Shortcuts in Tauri v2 — The Right Way and the Wrong Way

DEV Community·hiyoyo·19 days ago
#1Uga0XSG
Reading 0:00
15s threshold

All tests run on an 8-year-old MacBook Air. All results from shipping 7 Mac apps as a solo developer. No sponsored opinion. Global shortcuts in Tauri v2 changed significantly from v1. The plugin API is cleaner now, but there are still ways to get it wrong. Here's what I learned building a menubar app with a system-wide shortcut. The basics Add the plugin: toml# Cargo.toml tauri-plugin-global-shortcut = "2" json// package.json "@tauri-apps/plugin-global-shortcut": "^2.0.0" Register in main.rs: rustuse tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut}; tauri::Builder::default() .plugin(tauri_plugin_global_shortcut::Builder::new().build()) .setup(|app| { let shortcut = Shortcut::new( Some(Modifiers::SUPER | Modifiers::SHIFT), Code::KeyH ); app.global_shortcut().register(shortcut)?; Ok(()) }) The wrong way: hardcoded shortcuts Hardcoding Cmd+Shift+H is fine for your machine. It's a conflict on someone else's machine where that shortcut is already taken by another app.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More