is it possible to trigger a key event on the DOMWindow or DOMDocument in javascript? Basically I am creating an browser extension to interact with a website and they have shortcut Key Events (similar to GMail) on performing specific actions. I have found other postings on how to properly trigger key events (Definitive way to trigger keypress events with jQuery) but they don't seem to work when sending the key events to the document/window.
So far I have tried:
var evt = document.createEvent("KeyboardEvent");
evt.initKeyboardEvent("keydown", true, true, window, false, false, false, false, 0, "o".charCodeAt(0))
window.document.dispatchEvent(evt);
and a jQuery implementation:
$(document).trigger({ type: 'keydown', which: "0".charCodeAt(0) });
I also tried doing "keydown", "keypress" and "keyup" in succession but that did not work either.
Any help would be greatly appreciated!
Thanks in advance.