I noticed that when you press and hold a letter key like A the keydown event is fired continuously as long as you hold it. However when you press and hold down shift, the event is fired only once. I want to base my application logic on that observation, but I don't know if it is a standard behavior in every browser. Can anyone confirm?
Unfortunately, this is not a standard behaviour that you can rely on. I did a quick test on a few browsers I had installed (IE Edge, IE 11, Chrome 55, all on a windows machine), where all 3 browsers auto-repeated the keydown event for both letter keys (like A
), and modifier keys (like shift
), contrary to what you state your browser does.
Consistent handling of keyboard events has always been difficult across different browsers, as documented by Jan Wolter here and Peter-Paul Koch here. Wolter writes about auto-repeat:
If a key is held down long enough it typically auto-repeats, and some additional events will be triggered on each autorepeat. On Macintosh and Linux systems, modifier keys usually don't auto-repeat, but on Windows systems they do
then Wolter goes on to list various exceptions to this.