title: What's the theory behind jQuery keypress, keydown, keyup black magic (on Macs)?
body: <p>I am confused about the various behaviors of <em>keypress</em>, <em>keydown</em>, and <em>keyup</em>. 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.</p>
  
  <p>@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.</p>
  
  <p>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 <kbd>esc</kbd> key should dismiss the form the same as clicking the cancel button, and because the form has a <code>&lt;textarea&gt;</code> on it, <kbd>cmd</kbd> + <kbd>enter</kbd> should be the same as clicking the <em>OK</em> button. It seems simple enough to use the <em>keypress</em> event. The problem is that Chrome doesn't call my <em>keypress</em> handler for the <kbd>esc</kbd> key or <kbd>cmd</kbd> + <kbd>enter</kbd>. It fires for <kbd>ctrl</kbd> + <kbd>enter</kbd> and <kbd>option</kbd> + <kbd>enter</kbd> and for alphanumerics, but not <kbd>cmd</kbd> + <kbd>enter</kbd>.</p>
  
  <p>So I'll use <em>keyup</em> instead. I get <em>keyup</em> for <kbd>esc</kbd>, and <em>keyup</em> for <kbd>cmd</kbd>, and <em>keyup</em> for <kbd>enter</kbd>, great. But I don't get <em>keyup</em> for the <kbd>enter</kbd> key while I'm holding down <kbd>cmd</kbd>.</p>
  
  <p>Third time's the charm, you might think <em>keydown</em> seems to work, but with <em>keydown</em>, 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?</p>