Hmm. So a simulation would be "as soon as user presses key, block moves forward, user presses key again to stop block." ?
In that case, how about abusing javascript's loose casting:
var animId = null;
function moveBlock() {do stuff}
function startMotion() {
animId = setInterval("moveBlock()", 42);
}
function stopMotion() {
clearInterval(animId);
animId = null;
}
function switchMotion() {
if(animId)
stopMotion();
else
startMotion();
}
Then, attached to your body tag, you have the event onkeydown="switchMotion()". Be careful with what happens when a user holds a key down. The casted Boolean value of a variable is true if it is anything other than the empty string "", the number 0, undefined, null, NaN, or the Boolean value false. See
http://developer.mozilla.org/en/docs/Cor==========================