Created
October 20, 2015 10:49
-
-
Save 0x333333/b1ba8b420b4c5a07d5bd 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
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