title: How to move an element via arrow keys continuously/smoothly?
body: <p>I'm making a primitive game with Javascipt for fun.  I have set up functions to move my character around when the arrow keys are pressed as follows:</p>
  
  <pre><code>document.getElementById("character").style.top = 0;
  document.getElementById("character").style.left = 0;
  
  document.body.onkeydown = function() {
  var e = event.keyCode,
      charTop = parseInt(document.getElementById("character").style.top),
      charLeft = parseInt(document.getElementById("character").style.left);
  
      if (e == 40) { //down function
          document.getElementById("character").style.top = (parseInt(document.getElementById("character").style.top)) + 10 + "px";
      } else if (e == 37) { //left function
          document.getElementById("character").style.left = (parseInt(document.getElementById("character").style.left)) - 10 + "px";
      } else if (e == 39) { //right function
          document.getElementById("character").style.left = (parseInt(document.getElementById("character").style.left)) + 10 + "px";
      } else if (e == 38) { //up function
          document.getElementById("character").style.top = (parseInt(document.getElementById("character").style.top)) - 10 + "px";
      }
  
  }
  </code></pre>
  
  <p>and it works, but not the way I'd like it to.  I find that if you hold down an arrow key, it will move once, wait a second, then continuously move until you let go.  I think what is causing this is Windows' built in function to repeat a pressed button at a speed set in Control Panel after a specified delay.</p>
  
  <p>I would prefer that the character move immediately and continuously without the delay.  I am not sure how to go about this.  I'd also like to be able to define how quickly to move again if the button is still pressed (it moves ten pixels at a time, and if it repeated too quickly it would fly across the screen).</p>
  
  <p>I know that Javascript is not really meant for game programming, but hopefully someone can think of a way around this!  Thanks!</p>