Search code examples
javascriptjquerykeydownkeyup

Holding down arrows key constantly triggers keyUP event


Here's all I'm doing:

$(document).keydown(function(e) {
    e.preventDefault();
    console.debug(e.keyCode, "down");
});
$(document).keyup(function(e) {
    e.preventDefault();
    console.debug(e.keyCode, "up");
});

You can see the problem here: http://jsfiddle.net/pJgyu/32530/

If I hold down a letter key, keydown is fired constantly until I let go. Then keyup fires once. That seems like the correct behavior.

If I hold down an arrow key, keydown and keyup alternate constantly. Why is keyup firing?

I've tried it without the "e.preventDefault();".

Also, after holding an arrow key, SOMETIMES letter keys display the same strange behavior.


Solution

  • Your keyboard may be broken. I don't have that issue when I try to replicate it in your jsfiddle.