shortcut.rs 674 B

123456789101112131415161718192021
  1. //! Add global shortcuts to your app while a component is active
  2. //!
  3. //! This demo shows how to add a global shortcut to your app that toggles a signal. You could use this to implement
  4. //! a raycast-type app, or to add a global shortcut to your app that toggles a component on and off.
  5. //!
  6. //! These are *global* shortcuts, so they will work even if your app is not in focus.
  7. use dioxus::desktop::use_global_shortcut;
  8. use dioxus::prelude::*;
  9. fn main() {
  10. dioxus::LaunchBuilder::desktop().launch(app);
  11. }
  12. fn app() -> Element {
  13. let mut toggled = use_signal(|| false);
  14. _ = use_global_shortcut("ctrl+s", move || toggled.toggle());
  15. rsx!("toggle: {toggled}")
  16. }