-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shortcuts: Mac-native keyboard shortcuts #757
Comments
The common way to show command in UIs is to use the cloverleaf icon, which is what is also on the keyboard. (Similar to how "control" is often "Ctrl" for non-Mac computers.) Here are the command shortcuts as referenced on a Mac:
Here's how it looks like when referenced in a menu (from Safari, the web browser): However, if I look in the docs and even on Apple's website, it's written out like this: It's probably fine to just swap the word "Ctrl" with "Command" instead of using ⌘, as Apple keyboards have had both words and symbols for decades. For example: https://www.apple.com/shop/product/MK2A3LL/A/magic-keyboard-us-english They even use the English words for modifier keys on other language keyboards: https://www.apple.com/shop/product/MK2A3D/A/magic-keyboard-german https://www.apple.com/shop/product/MK2A3UA/A/magic-keyboard-ukrainian (They used to use "Cmd" instead of "Command", but write it out fully these days.) |
This can be tested with the metaKey attribute of a keyboard event: You could do something like: const isApple = /Mac|iPhone|iPad|iPod/.test(navigator.platform);
const ctrlEvent = isApple ? event.metaKey : event.ctrlKey;
const ctrlString = isApple ? "Command" : "Ctrl";
const altString = isApple ? "Option" : "Alt"; or check inline (with the if (isApple ? event.metaKey : event.ctrlKey) {
/* Stuff */
} (Although mapping it like above in one place is probably easier, simpler since it's probably used in multiple places.) Thankfully, "Option" on macOS is exactly equivalent to the "Alt" key, except for the string. Note: Yes, we need to check for iPhones and iPads too, not just macOS, as all of them can have a keyboard, and iPads have even have official hardware keyboards. Note 2: Checking for Meta key works on Windows and Linux too, but sometimes the OS handles the key instead, like on some versions of Windows with some browsers. (Firefox recently changed on Windows, apparently, and can intercept and detect it now.) On Linux, GNOME handles the key press before Firefox (and presumably other browsers, which I haven't checked yet). But other browsers and environments may differ. In other words, we need explicit detection for handling it (we can't say if one or the other) and we need explicit detection anyway for displaying Command+Option instead of Ctrl+Alt. |
Basically, everyone using a Mac or iPad/iPhone with a keyboard would expect shortcuts to work like this. This is how native apps and other web apps handle this. (Yeah, I know... *sigh*) |
On macOS, the keyboard shortcuts are still using command instead of Command. To fix this:
The text was updated successfully, but these errors were encountered: