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.
Advertisement
Answer
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.