save keydown in array and executes
<p>im creating a simple 2d game, and I want save the keydown keys into array, and execute them inisde a loop, so the user can hold a key and make it look like the chartater is moving non stop.</p>

<p>i got a setInterval function that act like a game Timer, and it just loop it self all the time. i added a listener and an array to hold the key.</p>

<p>I checked the keys inside the array and it look fine but, the functions moveRight and moveLeft are not working for some reson.</p>

<p>here is the code:</p>

<pre><code>      this.keysPressed = new Array();
      InitGameLoop: function () {
        var that = this;
        setInterval(function () {
            $(document).keydown(function (e) {
                var key = e.which;
                that.keysPressed.push(key);
                for (var i = 0; i &lt; that.keysPressed.length; i++) {
                    if (that.keysPressed[i] == 38) {
                        that.moveRight(worldWidth, 10);
                    }
                    else if (that.keysPressed[i] == 37) {
                        that.moveLeft(10);
                    }
                    log(that.keysPressed, that.yPos);
                    that.keysPressed.pop();
                }
            });
        }, 60);
</code></pre>

<p>my questions are:</p>

<ol>
<li>what am i doing worng?</li>
<li>is this a good idea? (if not, please feel free to recommend me about another :) )</li>
</ol>

<p>(sorry for my english)</p>
