Aaron Greenlee

Tagged in

notes

🚀

How to determine if the key pressed is printable using a web browser's keyboard event such as onKeyDown and the `event.key` property

Background There once was a time when you might bind a function to a onKeyDown event and quickly ignore a range of inputs by using the event.keyCode property. For example, you could check the value of event.keyCode and determine that you can ignore the key press event because the value was less than 29. Numbers made it easy. The code for the spacebar key was 32 and then the next range of printable characters you might care about started at 48 and went up to 90 and so on....