Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Created March 12, 2014 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanplopes/9499924 to your computer and use it in GitHub Desktop.
Save juanplopes/9499924 to your computer and use it in GitHub Desktop.
Este script provavelmente joga 2048 melhor que você
var sendSingle = function(key) {
var event = new KeyboardEvent('keydown');
Object.defineProperty(event, 'keyCode', {get : function() {return key;}});
Object.defineProperty(event, 'which', {get : function() {return key;}});
document.dispatchEvent(event);
}
var i = 0;
handle = setInterval(function() {
console.log(i);
if (i == 0)
sendSingle(37);
if (i == 1)
sendSingle(40);
if (i == 2)
sendSingle(39);
if (i == 3)
sendSingle(40);
i = (i+1)%4;
}, 50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment