Last active
August 29, 2015 13:57
-
-
Save Havoc24k/9742873 to your computer and use it in GitHub Desktop.
Set sequence and interval, paste in web console and run.
This file contains 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 intervalID; | |
var left = 37; | |
var up = 38; | |
var right = 39; | |
var down = 40; | |
var keyboardEvent = document.createEvent("KeyboardEvent"); | |
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent"; | |
var i = 0; | |
// set interval of execution and sequence of keystrokes | |
var interval = 500; | |
var sequence = [up, left, down, right]; | |
// clear the previous run | |
window.clearInterval(intervalID); | |
// set interval of execution | |
intervalID = window.setInterval(function () { | |
var keyCodeArg = sequence[i]; | |
keyboardEvent[initMethod]( | |
"keydown", // event type : keydown, keyup, keypress | |
true, // bubbles | |
true, // cancelable | |
window, // viewArg: should be window | |
false, // ctrlKeyArg | |
false, // altKeyArg | |
false, // shiftKeyArg | |
false, // metaKeyArg | |
keyCodeArg, // keyCodeArg : unsigned long the virtual key code, else 0 | |
0 // charCodeArgs : unsigned long the Unicode character associated with the depressed key, else 0 | |
); | |
document.dispatchEvent(keyboardEvent); | |
if (i < sequence.length - 1) { | |
i = i + 1; | |
} else { | |
i = 0; | |
} | |
}, interval); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment