github / hotkey

Trigger an action on an element with a keyboard shortcut.
https://github.github.com/hotkey/
MIT License
3.22k stars 97 forks source link

Add support for `Space` and `Plus` keywords #45

Closed laserlemon closed 1 year ago

laserlemon commented 3 years ago

It seems that the eventToHotkeyString function returns " " for a spacebar keystroke, as described in the key values docs. But the expandHotkeyToEdges function also uses the space character to split hotkey combinations.

So how might one define a single hotkey or hotkey combination containing a space?

We might consider a slight deviation from the key values docs in this instance to add the Space shorthand as an alias for " " when defining a hotkey via the data-hotkey attribute or install function. Thank you! 💛

theinterned commented 2 years ago

Maybe we could use "Space" as a way to distinguish space as a separator of key sequences (" "), and the literal space key as a shortcut ("Space").

So for example the shortcut key to open Spotlight / Alfred / Raycast on a Mac would be "Meta+Space".

theinterned commented 2 years ago

This actually relates to https://github.com/github/hotkey/issues/54#issuecomment-992997472 where I suggest we match on event.code rather than event.key. The event.key for space is " ": the event.code is "Space", so making that breaking change would also resolve this issue.

If we don't make that change, then this would require some special code.

iansan5653 commented 1 year ago

Updated this issue to also cover Plus (because Mod++ isn't great).

iansan5653 commented 1 year ago

Typo prevented this from properly closing when it was merged. It was released in 2.3.0