Skip to content

Instantly share code, notes, and snippets.

@jacekd
Created March 14, 2014 08:04
Show Gist options
  • Select an option

  • Save jacekd/9543753 to your computer and use it in GitHub Desktop.

Select an option

Save jacekd/9543753 to your computer and use it in GitHub Desktop.

Revisions

  1. Jacek Dominiak created this gist Mar 14, 2014.
    16 changes: 16 additions & 0 deletions 2048-random.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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);