Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/content/docs/plugin/global-shortcut.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,25 @@ pub fn run() {
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};

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| {
app.handle()
.plugin(tauri_plugin_global_shortcut::Builder::new().build())?;

app.global_shortcut().on_shortcut(
ctrl_n_shortcut,
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!");
}
ShortcutState::Pressed => {
println!("Ctrl-N Pressed!");
}
ShortcutState::Released => {
println!("Ctrl-N Released!");
}
}
}
})
.build(),
},
)?;

app.global_shortcut().register(ctrl_n_shortcut)?;
}
Ok(())
})
Expand Down