Closed Bug 1475137 Opened 7 years ago Closed 7 years ago

Add a property to identify Control events on event.key

Categories

(Developer Documentation Graveyard :: API: Miscellaneous, enhancement)

All
Other
enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: nehar2ka, Unassigned)

References

()

Details

(Whiteboard: [specification][type:feature])

What problem would this feature solve? ====================================== Help to avoid writing the string of the keys like "BackSpace", "Enter" in the control field. Who has this problem? ===================== Users of Javascript How do you know that the users identified above have this problem? ================================================================== There are stackoverflow questions where I have given a possible solution(definitely the only alternative and certain not clean) https://stackoverflow.com/questions/51296562/how-to-tell-whether-keyboardevent-key-is-a-printable-character-or-control-charac How are the users identified above solving this problem now? ============================================================ Stuck Do you have any suggestions for solving the problem? Please explain in detail. ============================================================================== Having a property to identify the control characters other than alphanumeric as a bunch of keys. Adding it to the key property of keyboardEvent Is there anything else we should know? ====================================== This is a basic requirement
nehar2ka: MDN Web Docs documents the web API, and making changes to the API is out of scope - that's part of the standardization process. According to MDN, KeyboardEvents are part of the UI Events specification [1]. They go into their reasoning for removing keycode and charCode In 4.6.1.2, KeyboardEventInit [2]: In practice, keyCode and charCode are inconsistent across platforms and even the same implementation on different operating systems or using different localizations. This specification does not define values for either keyCode or charCode, or behavior for charCode. In conforming UI Events implementations, content authors can instead use key and code. Later, in 7. Legacy Key & Mouse Event Attributes [3]: The large amount of legacy content, including script libraries, that relies upon detecting the user agent and acting accordingly means that any attempt to formalize these legacy attributes and events would risk breaking as much content as it would fix or enable. Additionally, these attributes are not suitable for international usage, nor do they address accessibility concerns. So, I don't think you will get far adding new attributes like this with the standards bodies. There is contact information in the specification if you want to pursue this further. I think you will have more success by using a popular keyboard event library, which has already tackled these issues. Searching for "javascript keyboard event library" returns many hits, including a "Which is the best JavaScript Keyboard event library" [4] and "10 JavaScript Libraries to Handle Keyboard Events" [5]. It is possible that the KeyboardEvents docs should talk more about .keyCode and .charCode being deprecated, but that would be better handled with a new bug. [1] https://w3c.github.io/uievents/ [2] https://w3c.github.io/uievents/#idl-keyboardeventinit [3] https://w3c.github.io/uievents/#legacy-key-attributes [4] https://stackoverflow.com/questions/2353417/which-is-the-best-javascript-keyboard-event-library-hotkeys-shortcuts [5] https://codegeekz.com/10-javascript-libraries-to-handle-keyboard-events/
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Component: Events → API: Miscellaneous
Product: developer.mozilla.org → Developer Documentation
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.