How do I avoid multiple key up/down/press events when holding a key?

Posted by Rammay on Stack Overflow See other posts from Stack Overflow or by Rammay
Published on 2010-03-08T14:01:23Z Indexed on 2010/03/08 14:06 UTC
Read the original article Hit count: 201

I'm creating a web front end to control a small robot. Ajax calls will be made on a keydown, to start the robot, and keyup to stop it.

My problem is that when a key is held down the keyup, keydown, and keypress events seem to cycle continually. Does anybody know of a way to only have keydown fire when the key is first pressed and keyup to fire when it has been released?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about javascript-events