I am confused about the various behaviors of keypress, keydown, and keyup. It seems that I have missed an important piece of documentation, one that explains the subtleties and nuances of this trio. Could someone help me to figure out which document I need to read in order to more effectively use these events? In case you want details, see below.
@o.v.: you asked me to show some code, but it's not really a specific problem in the code that I'm trying to solve. I'm trying to get a handle on the behaviors of these event handlers and asking someone who understands them to point me to a good piece of documentation.
I use jQuery to build an input form and insert it into my document. It works just fine, mostly. I want the form to respond to the keyboard like most other input forms I see out there: the esc key should dismiss the form the same as clicking the cancel button, and because the form has a <textarea>
on it, cmd + enter should be the same as clicking the OK button. It seems simple enough to use the keypress event. The problem is that Chrome doesn't call my keypress handler for the esc key or cmd + enter. It fires for ctrl + enter and option + enter and for alphanumerics, but not cmd + enter.
So I'll use keyup instead. I get keyup for esc, and keyup for cmd, and keyup for enter, great. But I don't get keyup for the enter key while I'm holding down cmd.
Third time's the charm, you might think keydown seems to work, but with keydown, you get repeat keys. I know, all you have to do is unbind the handler the first time you're called, but it just seems weird that the three different event types would behave so differently. Why is this? Is there an obvious document out there that I obviously haven't read?