Skip to content

Instantly share code, notes, and snippets.

@jacekd
Created March 14, 2014 08:04
Show Gist options
  • Save jacekd/9543753 to your computer and use it in GitHub Desktop.
Save jacekd/9543753 to your computer and use it in GitHub Desktop.
2048 - random arrow play
function fireKey()
{
if(document.createEventObject)
{
var eventObj = document.createEventObject();
eventObj.keyCode = Math.floor(Math.random() * (40 - 37 + 1)) + 37;
document.fireEvent("onkeydown", eventObj);
}else if(document.createEvent)
{
var eventObj = document.createEvent("Events");
eventObj.initEvent("keydown", true, true);
eventObj.which = Math.floor(Math.random() * (40 - 37 + 1)) + 37;
document.dispatchEvent(eventObj);
}
}
setInterval(fireKey, 200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment