title: How can I avoid autorepeated keydown events in JavaScript?
body: <p>If the user holds down the key, multiple keydown events are fired. For usability reasons I need to use keydown, not keyup, but I want to avoid this situation. My relevant code is the following:</p>
  
  <pre><code>$(document).keydown(function(e) { 
          var key = 0;
  
  
          if (e == null) { key = event.keyCode;}  
          else {  key = e.which;} 
  
  
          switch(key) {
              case config.keys.left:                
                goLeft();
                break;
              case config.keys.up:                        
                goUp();
                break;
              case config.keys.right:                     
                goRight();
                break;
              case config.keys.down:                
                goDown();
                break;
              case config.keys.action:              
                select();
                break;
          }     
        });
  </code></pre>
  
  <p>So when the user holds down the down key, for example, goDown() is fired multiple times. I would like it to fire just once even if the user holds the key down.</p>