Well, when you hold a key on your keyboard, after the first fire there is a 1sec delay.
You can go ahead and open notepad and hold a key (e.x ‘x’) you’ll see after the first fire there is a delay.
However, I’m trying to develop a game in HTML5 Canvas with JavaScript, and that 1sec delay is very annoying, Additionally, it stops the player walking animation..
So how can I delete that annoying delay in JavaScript ( no jQuery! ) ?
My keydown event works in this pattern –
document.onkeydown = getKey;
function getKey(e) {
switch(e.keyCode) {
case 38: // UP
Player.PositionY--;
break;
case 39: // RIGHT
Player.PositionX++;
break;
case 40: // DOWN
Player.PositionY++;
break;
case 37: // LEFT
Player.PositionX--;
break;
}
}
you could start an event on
keydownand stop it onkeyup