Discussion:
keyup() fires multiple times?
Keith Hughitt
2010-01-05 20:38:48 UTC
Permalink
Hi all,

I'm creating a method for the first time which causes some action to
happen while a key is pressed. I've noticed, however, that the 'keyup'
event which I would normally use to determine when the key is
released is fired continually, even when the key is still being
pressed.

e.g.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<title>jQuery > Keyup Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
$(function () {
$(document).keydown(function (e) {
console.log("keydown");
}).keyup(function (e) {
console.log("KEYUP");
});
});
</script>
</body>
</html>

Instead of seeing "keydown", "keydown"..."keydown", "KEYUP". It
switches back and forth between the two continually. So far I've
tested the same demo in FF 3.5, 3.7 and Chrome 3.x.

Any ideas?

Thanks!
Keith Hughitt
2010-03-01 16:03:57 UTC
Permalink
Looks like the problem is OS-specific. In Ubuntu 9.10, for example,
there is an option that is enabled by default in the user's keyboard
preferences
which causes key-holds to simulate multiple key-presses. Turning this
off results in the expected behavior. On Windows, the default behavior
is for key-holds to behave like key-holds so no problem exists.

Any suggestions for normalizing behavior across platforms?

Keith
Post by Keith Hughitt
Hi all,
I'm creating a method for the first time which causes some action to
happen while a key is pressed. I've noticed, however, that the 'keyup'
event which I would  normally use to determine when the key is
released is fired continually, even when the key is still being
pressed.
e.g.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
        <title>jQuery > Keyup Test</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
jquery.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
$(function () {
    $(document).keydown(function (e) {
        console.log("keydown");
    }).keyup(function (e) {
        console.log("KEYUP");
    });});
</script>
</body>
</html>
Instead of seeing "keydown", "keydown"..."keydown", "KEYUP". It
switches back and forth between the two continually. So far I've
tested the same demo in FF 3.5, 3.7 and Chrome 3.x.
Any ideas?
Thanks!
Loading...