From 696af68c9bcbd763f0e04c776c0eb7964829b422 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Mon, 19 Feb 2024 15:44:38 +0200 Subject: [PATCH] docs(global-shortcut): update examples in README.md closes #965 --- plugins/global-shortcut/README.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/plugins/global-shortcut/README.md b/plugins/global-shortcut/README.md index bb6b28ebd..5886b9b65 100644 --- a/plugins/global-shortcut/README.md +++ b/plugins/global-shortcut/README.md @@ -56,7 +56,20 @@ fn main() { tauri::Builder::default() .setup(|app| { #[cfg(desktop)] - app.handle().plugin(tauri_plugin_shortcut::init())?; + { + use tauri_plugin_shortcut::{Shortcut, Code, Modifiers}; + + let alt_d_shortcut = Shortcut::new(Some(Modifiers::ALT), Code::KeyD); + app.handle().plugin( + tauri_plugin_shortcut::Builder::::with_handler(move |app, shortcut| { + if shortcut == &alt_d_shortcut { + println!("Shortcut triggered"); + } + }) + .build() + )?; + } + Ok(()) }) .run(tauri::generate_context!()) @@ -64,10 +77,13 @@ fn main() { } ``` -Afterwards all the plugin's APIs are available through the JavaScript guest bindings: +Afterwards all the plugin's APIs are available through the JavaScript bindings: ```javascript - +import { register } from "@tauri-apps/plugin-global-shortcut"; +await register("CommandOrControl+Shift+C", () => { + console.log("Shortcut triggered"); +}); ``` ## Contributing