gaucho-labs / leptos-hotkeys

a declarative way of using keyboard shortcuts + callbacks in leptos applications
https://leptos-hotkeys.vercel.app
MIT License
43 stars 8 forks source link

Spacebar key not working #93

Closed boyswan closed 4 months ago

boyswan commented 5 months ago

With event: web_sys::KeyboardEvent, event.key() is " " for space which does not work.

I have tried both string and char:

  use_hotkeys!((" ", ' ') => move |_| {
    leptos::logging::log!("hit");
  });

Perhaps the ability to configure using event.key vs event.code is needed for this, as in this case event.code() == "Spacebar"

friendlymatthew commented 4 months ago

Thanks @boyswan, I've decided to use code https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code as our key identifier. A note, it is good to have the debug feature flag turned on, this way you can see the pressed key codes in your browser console :)

I've had thoughts about strongly typing these keys, but due to all the variance, I felt the authors left it as a String intentionally. What do you think?