mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-22 21:30:44 +02:00
docs(global-shortcut): add registering example
This commit is contained in:
@@ -57,17 +57,20 @@ fn main() {
|
|||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
#[cfg(desktop)]
|
#[cfg(desktop)]
|
||||||
{
|
{
|
||||||
use tauri_plugin_shortcut::{Shortcut, Code, Modifiers};
|
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut};
|
||||||
|
|
||||||
let alt_d_shortcut = Shortcut::new(Some(Modifiers::ALT), Code::KeyD);
|
let ctrl_n_shortcut = Shortcut::new(Some(Modifiers::CONTROL), Code::KeyN);
|
||||||
app.handle().plugin(
|
app.handle().plugin(
|
||||||
tauri_plugin_shortcut::Builder::::with_handler(move |app, shortcut| {
|
tauri_plugin_global_shortcut::Builder::with_handler(move |_app, shortcut| {
|
||||||
if shortcut == &alt_d_shortcut {
|
println!("{:?}", shortcut);
|
||||||
println!("Shortcut triggered");
|
if shortcut == &ctrl_n_shortcut {
|
||||||
}
|
println!("Ctrl-N Detected!");
|
||||||
})
|
}
|
||||||
.build()
|
})
|
||||||
)?;
|
.build(),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
app.global_shortcut().register(ctrl_n_shortcut)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user