0

I am writing a program that intercepts user’s keystrokes to decide whether to display or reject the characters. The keypress event is more convenient for this analysis than keyup and keydown because I analyze only letters and digits, all other characters and their combinations are allowed to go through. Meanwhile, https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/ recommends keydown and keyup against keypress. It says “Moreover, the keypress event has been deprecated. This is a big enough reason to avoid it.” How important is it to avoid deprecated features? What happens if I use them? Thank you for your help.

Victor
  • 5
  • 2
  • 4
    You're not talking about *JavaScript* features: those are *browser* features. The reason to avoid them is that they may disappear someday and your code will not work anymore. – Pointy Jun 17 '22 at 14:03
  • Thank you Pointy! I wonder what do other developers do? Do they rush to replace onkeypress in their HTML and keypress in their addEventListener functions? What would you do if faced with this problem? – Victor Jun 19 '22 at 15:20
  • I would not necessarily "rush to replace", but I would not use a deprecated API or feature in *new* code. – Pointy Jun 19 '22 at 15:21
  • OK, thanks, will continue to struggle. – Victor Jun 20 '22 at 16:59

1 Answers1

1

The keypress event has been marked as deprecated by MDN and W3C This means that browser may not support this functionality in future releases, and possible bugs are most likely not patched anymore.

You can still use keypress event in your code, but some day your code stops working because the browser you are using no longer supports it. When this day will be is impossible to say. Could be next month, next year or longer.

n9iels
  • 867
  • 7
  • 21