# How the keypress Event Differs Between Chrome, Safari, IE10, and Firefox

DevFeed: [How the keypress Event Differs Between Chrome, Safari, IE10, and Firefox](<https://devfeed.tech/articles/keypress-is-bananas-35527.md>)

Original publisher: [Read original article](<https://meowni.ca/posts/keypress-is-bananas/>)

Author: Monica Dinculescu

Published: 2015-06-02T00:00:00Z

Content type: article

Language: en

Sources: [Monica Dinculescu](<https://devfeed.tech/sources/monica-dinculescu.md>)

Topics: [keyboard](<https://devfeed.tech/topics/keyboard.md>), [browsers](<https://devfeed.tech/topics/browsers.md>), [Chrome](<https://devfeed.tech/topics/chrome.md>), [Firefox](<https://devfeed.tech/topics/firefox.md>), [deprecated](<https://devfeed.tech/topics/deprecated.md>)

Tags: [browsers](<https://devfeed.tech/tags/browsers.md>), [chrome](<https://devfeed.tech/tags/chrome.md>), [code](<https://devfeed.tech/tags/code.md>), [deprecated](<https://devfeed.tech/tags/deprecated.md>), [firefox](<https://devfeed.tech/tags/firefox.md>), [keyboard](<https://devfeed.tech/tags/keyboard.md>)

## AI overview

This article examines inconsistent keypress event behavior across browsers. Chrome, Safari, and IE10 emit keypress for printable characters, while Firefox 38 emits it for all typed input. It also discusses differences and deprecation involving keyCode, charCode, and key.

## Source excerpt

The keypress event works maddeningly differently in Chrome/Safari and Firefox, and this is the story of how I spent two hours discovering that, so that hopefully you don't have to. Keypress what? A keypress event is one of the events you get when you mash on the keyboard. It's special because according to the spec, you should only get a keypress event for keystrokes that produce printable characters. So you'll get it for things like letters and symbols, but not for backspace and left arrow. It's a great event to have if you want to write some as-you-type validation on an input, and you want to be able to dismiss the non-printable characters (which will still generate key events, but are uninteresting to the validation bit). Chrome, Safari and IE10 agree with this interpretation, which is great news. To be contrarian, Firefox (38; I don't know about Aurora) always sends a keypress event for anything you type. It's basically a keydown event from what I see. Now you have to get rid of control characters yourself and you get write code that doesn't make sense on the other platforms! Yay! (not yay) I call shenanigans. Mind your keyCodes and charCodes From looking at the spec, we expect a keypress event to have: keyCode, a number code that represents the key you've pressed. For example, q is 113. This is allegedly deprecated, but don't worry, both Firefox and Chrome implement it, but differently. charCode, the unicode number of the key. This code only exists for keypress. Like before, it's deprecated, but like before, it's implemented by both browsers. Differently. key, the value of the key represented by the event. According to that spec, this one is unimplemented. Worry not, Firefox implements it just fine (Chrome doesn't). It is the hero we deserve, but not the one we get right now. 😭 What you get out of this is spectacularly annoying. I wrote some code that basically prints out what the keypress event looks like, and found: As promised, in Chrome/Safari/IE10, we only