Skip to content

Instantly share code, notes, and snippets.

@0x333333
Created October 20, 2015 10:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x333333/b1ba8b420b4c5a07d5bd to your computer and use it in GitHub Desktop.
Save 0x333333/b1ba8b420b4c5a07d5bd to your computer and use it in GitHub Desktop.
AutoClick = {};
AutoClick.keydown = function(k) {
var oEvent = document.createEvent('KeyboardEvent');
Object.defineProperty(oEvent, 'keyCode', {
get : function() {
return this.keyCodeVal;
}
});
Object.defineProperty(oEvent, 'which', {
get : function() {
return this.keyCodeVal;
}
});
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;
if (oEvent.keyCode !== k) {
alert("keyCode mismatch " + oEvent.keyCode + "(" + oEvent.which + ")");
}
document.dispatchEvent(oEvent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment