DEPRECATED: Using keypress To Detect Keyboard Events In JavaScript
December 2020
DEPRECATED
The code on this page uses keypress events. Those have been deprecated in favor of keydown and keyup.
You should use those instead.
Old Notes
This is the original approach I used to detect keyboard events on web pages:
HTML
Output
JavaScript
const inputEl = document.
inputEl.
Check the console for the output.
end of line