View Full Version : EventObject getCharCode() Duplicates

23 Feb 2010, 8:27 AM
I have an instance of Ext.form.TextArea with enableKeyEvents set to true. I have a listener set to listen to the keyup event. Within this keyup event I capture the key using the getCharCode() and then do different things with that code.

For instance, when someone presses shift+9 (to get '(' ) it returns a code of 40.

Also, when someone press the down arrow it returns a code of 40.

Now I can filter this by seeing if isNavKeyPress() returns true then it's the down error else it's ')'. But should I need to do this extra step?

23 Feb 2010, 9:10 AM
keydown and keyup events shouldn't generate charCodes.

you should be listening on the keypress event instead.
that said, however, you'd still need to filter out special keys (e.g. arrow keys, which should not generate charCodes) as you've mentioned.

this seems like the only sane way atm.

here's a quote from a very useful site which i use for all my key handling needs:

To understand the difference between keydown and keypress, it is useful to distinguish between "characters" and "keys". A "key" is a physical button on the computer's keyboard. A "character" is a symbol typed by pressing a button. On a US keyboard, hitting the 4 key while holding down the Shift key typically produces a "dollar sign" character. This is not necessarily the case on every keyboard in the world. In theory, the keydown and keyup events represent keys being pressed or released, while the keypress event represents a character being typed. In practice, this is not always the way it is implemented.