Created
July 12, 2018 21:46
-
-
Save JokingChicken/a5a3698328ad08a86f21f87eb330fbe2 to your computer and use it in GitHub Desktop.
press a key in html
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
function openf12() { | |
var keyboardEvent = document.createEvent("KeyboardEvent"); | |
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent"; | |
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 | |
123, // 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment