jQuery document handlers stealing key presses in input fields
<p>This question has probably been asked before, but I am not able to find a suitable search phrase to locate it, either here or on the intertubes.</p>

<p>I have a web page for a game which uses the keyboard, so with jQuery I have set handlers in the document:</p>

<pre><code>$(document).keydown(myKeydown);
$(document).keyup(myKeyup);
$(document).blur(myBlur);
</code></pre>

<p>But now any text written in an input field is stolen by the document event handlers, and characters only reach the input if they are not used in the document handlers. These handlers in essence look like this:</p>

<pre><code>function myKeydown(event)
{
    if (event.which == 65)
    {
        console.log('a pressed');
        return false;
    }
    return true;
}
</code></pre>

<p>Now imagine that I have a text input box; if I press any key other than 'a' it shows in the input, but not 'a' (since myKeydown is "eating" it by returning false). I could return true in any case, but then if no input box is focused I get weird things like "search when you type", if enabled.</p>

<p>I have tried to add handlers for the input box:</p>

<pre><code>input.keydown(function() { console.log('down'); return false; });
input.keyup(function() { console.log('up'); return false; });
input.blur(function() { console.log('blur'); return false; });
</code></pre>

<p>With this code I get the console.logs, but of course keys don't reach the box (because I am doing nothing with the presses). Can I send these events somewhere so the corresponding keys appear in the input box?</p>

<p><strong>Note:</strong> some people have suggested to use <code>event.stopPropagation()</code> instead of <code>return false</code>. <a href="http://api.jquery.com/bind/" rel="nofollow">jQuery docs</a> say:</p>

<blockquote>
  <p>Returning false from a handler is equivalent to calling both .preventDefault() and .stopPropagation() on the event object."</p>
</blockquote>

<p>That is precisely what I want: to prevent "search as you type" from kicking in, I have to prevent the default action, which is to type on an input and to "search as you type" on the page.</p>

<p>(Also, for some reason the <code>keydown</code> event handler does not have a stopPropagation() function on Firefox latest.)</p>
