Created
June 29, 2014 05:19
-
-
Save ruiwen/d07f2f94c56572cbb40d 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
function keypress(n) { | |
var keyboardEvent = new KeyboardEvent('keydown', {bubbles:true}); | |
Object.defineProperty(keyboardEvent, 'charCode', {get:function(){return this.charCodeVal;}}); | |
Object.defineProperty(keyboardEvent, 'keyCode', {get: function(){return this.charCodeVal;}}); | |
keyboardEvent.charCodeVal = n; | |
document.body.dispatchEvent(keyboardEvent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment