logoalt Hacker News

f33d5173today at 3:58 PM0 repliesview on HN

The real issue here is first that browsers don't expose a simple way to check for key combinations and second that developers don't bother building their own. You'll find on any number of sites that an intended key combination can also be invoked with additional modifiers of alt or shift or whatnot. Even here, the code shown only fixes the broader issue on windows; alt+cmd+s still gets blocked.

There should be a proposal for browsers to expose a property on the keydown/up/press event containing a code for the key combination. Something like "CTRL+S", "CTRL+ALT+S", etc. The programmer could then switch over this property rather than having to check key codes and modifiers manually.

I would also propose to any web developers that they build this property themselves in their own code and check against it instead of checking modifiers directly. Not only would it protect against bugs like in the OP, it would also be a lot more convenient to use.