title: Best way to capture all key events for a web application?
body: <p>I'm a little distraught at the current state of key capturing for web applications. It works great as long as you know your user is going to be typing in a specific place (e.g. an <code>input</code> field), but as soon as you want to do global shortcuts for an entire &quot;application&quot;, it seems to fall apart.</p>
  <p>I'm trying to find out if there is a better way to capture <em>all</em> the key events for a web page than the method I am currently using.</p>
  <p>My current method is to use the <a href="https://github.com/jeresig/jquery.hotkeys" rel="nofollow noreferrer">JQuery Hotkeys</a> plugin, bound to the <code>document</code> element, i.e.:</p>
  <pre><code>$(document).bind(&quot;keyup&quot;, &quot;delete&quot;, function() {});
  </code></pre>
  <p>That works great for most purposes, but for example on Firefox, if the user happens to absentmindedly move their mouse over the navigation bar, the delete key will sometimes result in the user going &quot;back&quot;, and the key is never received by the handler so that I can stop propagation.</p>
  <p>Is there a different element I should be binding to? Is there a better plugin out there for this? Should I just avoid using any keys that are bound to things in common web browsers?</p>
  <p>As more and more web applications look to mimic their desktop counterparts, it seems like this is a basic feature that web developers will increasingly require.</p>
  <p><strong>EDIT:</strong> I should point out that I am already using <code>e.stopPropagation()</code> and <code>e.preventDefault()</code>. The main problem seems to be that sometimes the event is never even passed to the bound function. I am basically wondering if anyone has figured out a &quot;higher&quot; element to bind to other than <code>document</code>. Or is there an alternative I have never even thought of? Embedding an invisible Flash element on the page and then passing all keys from that to JavaScript, for example (I don't think this would work).</p>
  <p>I think, at this point, I am doing things the &quot;standard, well-known way.&quot; I am trying to see if there is an outside-the-box way that isn't widely known that maybe someone on Stack Overflow knows about :-).</p>