KeyboardEvent#key is supposed to report the key character that was pressed. The spec - specifically 5.3.2 "modifier keys" (https://www.w3.org/TR/uievents/#keys-modifiers) shows that if the `shiftKey` is true, then the `event.key` value should be in its "shifted state" - this includes when pressed in combination with other keys - for example `metaKey` (in Example 24 (https://www.w3.org/TR/uievents/#example-aa6d4cea) they use `ctrlKey` and `shiftKey`). Safari misreports this, contrary to other browsers. An example: ``` // Pressing Shift+P results in: event.shiftKey && event.key === 'P' // Pressing Ctrl+Shift+P results in: event.ctrlKey && event.shiftKey && event.key === 'P' // Pressing Cmd+Shift+P results in: event.metaKey && event.shiftKey && event.key === 'p' // lowercase, incorrect ``` To compare Firefox, Chrome, report the following: ``` // Pressing Shift+P results in: event.shiftKey && event.key === 'P' // Pressing Ctrl+Shift+P results in: event.ctrlKey && event.shiftKey && event.key === 'P' // Pressing Cmd+Shift+P results in: event.metaKey && event.shiftKey && event.key === 'P' // uppercase, correct ```
I've just tested this in Safari 11 TP and this bug is also present there.
I don't think that this is a bug. If you look in the Keyboard Viewer <https://support.apple.com/kb/PH25242?locale=en_US>, you can see that the Cmd+Shift plane is lower case on the Mac, so this is what WebKit exposes.
It's a bug in as much as every other browser on Mac represents the keys in upper case, and the spec for event.key has examples showing the ctrl/cmd+shift+letter keys use their uppercase variants.
We should get the spec examples fixed. Diverging from native behavior would be a bad idea, both because it would be confusing, but also because it actually matters and makes writing reliable software easier.
Mass move bugs into the DOM component.
I want to argue that conforming to other platforms and browsers is more important than conforming to the native behavior. Safari runs web apps, which target the web in general, and having to special-case key handling per platform is antithetical to that. Specifically, I maintain a library that allows client code to specify key maps, and uses KeyboardEvent.key in its key dispatching logic. Having such bindings work differently across browsers and platforms is obviously causing problems for my users.
It looks like this was fixed back in Chrome 62, via a related bug: https://crbug.com/747358. As far as my testing today goes, all browsers report consistently that `event.metaKey && event.shiftKey && event.key === 'p'`
It's not really fixed, as per the original bug description—it rather seems like other browsers have regressed to also behave in the incorrect way. From some of the related bugs, it seems that macOS makes it very hard to get the correct character in this case, so maybe that's how this happened. But I don't think this issue can be considered solved.