Hacker News new | ask | show | jobs
by f33d5173 34 days ago
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.

1 comments

This bug comes from a programmer trying to fix one problem - users press Control S and get a save dialog - by altering some fundamental and bug-prone behaviour.

Imagine the damage programmers could do if they had more options to meddle easily! They have low-level APIs if they need them to hook keys. Best leave it at that.

Meanwhile, there is the accesskey attribute in HTML to let you customise shortcut keys: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...

> the accesskey attribute

Holy crow what a mess. No wonder I'd never heard of this.