Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created June 24, 2013 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jutememo/5847201 to your computer and use it in GitHub Desktop.
Save jutememo/5847201 to your computer and use it in GitHub Desktop.
var event = document.createEvent("KeyEvents");
event.initKeyEvent("keypress",
true,
true,
null,
false, // holds Ctrl key
true, // holds Alt key
false, // holds Shift key
false, // holds Meta key
0, // presses a special key, @see http://mxr.mozilla.org/mozilla/source/dom/public/idl/events/nsIDOMKeyEvent.idl
event.DOM_VK_0 // presses a normal key, e.g. "A".charCodeAt(0),
);
document.documentElement.dispatchEvent(event);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment