function doKeyDown(event) { switch (event.keyCode) { case 32: /* Space bar was pressed */ if (x == 4) { setInterval(drawAll, 20);
Use setTimeout(drawAll, 20) instead. That only executes the function once.
setTimeout(drawAll, 20)