hotkey icon indicating copy to clipboard operation
hotkey copied to clipboard

Add a special `Mod` character that translates to either `Meta` on Mac or `Control` on other platforms

Open theinterned opened this issue 4 years ago • 2 comments

There are many cases where we want to be able to support either the Meta or Control modifier for a shortcut; as opposed to cases where we support both Meta and Control.

One way to handle this would be to add a special Mod character that would map to Meta on Mac / iOS, and Control on Window or Linux.

<button data-hotkey="Mod+s">Save</button>

would map to Meta+s on Mac / Control+s otherwise.

theinterned avatar Dec 08 '21 23:12 theinterned

One wrinkle to this is how macOS always renders event.key as lowercase when the metaKey is pressed, regardless of shiftKey. This means the event.key for Mod+Shift+/ for example would be ? when Control+Shift is pressed but / when Meta+Shift is pressed.

See https://github.com/github/hotkey/issues/54#issuecomment-991353720 and https://github.com/github/hotkey/pull/43

Screen Shot 2021-12-10 at 5 57 36 PM

Notice above that when the Control+Meta+Shift are pressed together the result is an upper case event.key! 🤔

theinterned avatar Dec 10 '21 22:12 theinterned

Note this would probably involve a comparison function (which we could also export) so that we could match hotkeys like so:

const isEventMatch = hotkeyCompare(eventToHotKeyString(event), 'Mod+k');

theinterned avatar Dec 16 '21 15:12 theinterned