Skip to content

Commit

Permalink
docs(global-shortcut): update examples in README.md closes #965
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Feb 19, 2024
1 parent 51ba4c5 commit 696af68
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions plugins/global-shortcut/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,34 @@ 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!())
.expect("error while running tauri application");
}
```

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
Expand Down

0 comments on commit 696af68

Please sign in to comment.