Created
March 13, 2014 10:59
-
-
Save johnste/9526331 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keydown = function(k) { | |
var oEvent = document.createEvent('KeyboardEvent'); | |
// Chromium Hack | |
Object.defineProperty(oEvent, 'keyCode', { | |
get : function() { | |
return this.keyCodeVal; | |
} | |
}); | |
Object.defineProperty(oEvent, 'which', { | |
get : function() { | |
return this.keyCodeVal; | |
} | |
}); | |
var no = {get : function() {return false;}} | |
Object.defineProperty(oEvent, 'shiftKey', no); | |
Object.defineProperty(oEvent, 'metaKey', no); | |
if (oEvent.initKeyboardEvent) { | |
oEvent.initKeyboardEvent("keydown", true, true, document.defaultView, false, false, false, false, k, k); | |
} else { | |
oEvent.initKeyEvent("keydown", true, true, document.defaultView, false, false, false, false, k, 0); | |
} | |
oEvent.keyCodeVal = k; | |
document.dispatchEvent(oEvent); | |
} | |
var index = 0; | |
setInterval(function() { | |
var loop = [37, 40, 39, 40]; | |
index++; | |
keydown(loop[index%loop.length]); | |
}, 20); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment