title: Firing a keyboard event on Chrome
body: <p>I'm trying to fire a keyboard event to a page using javascript on Chrome.
  I had an approach that used to work on Firefox:</p>
  
  <pre><code>pressKey = function(key, shift) {
    var evt = document.createEvent('KeyboardEvent');
    evt.initKeyEvent("keypress", false, true, null, false, false,
                     shift, false, keyCode(key), key.charCodeAt(0));
    document.dispatchEvent(evt);
  }
  </code></pre>
  
  <p>where key is the desired key and keyCode changes lowercase letters into highercase and also calls charCodeAt().</p>
  
  <p>My problem is that events on Safari/Chrome don't have initKeyEvent, but initKeyboardEvent. The main difference I could notice was that you have to pass the key as a keyIdentifier (which looks like a unicode character) instead of passing the keycode and the keychar. Nonetheless I still can't manage to make it work.</p>
  
  <p>I've also tried the JQuery approach described <a href="https://stackoverflow.com/questions/832059/definitive-way-to-trigger-keypress-events-with-jquery/832121#832121">here</a> without success.</p>
  
  <p><strong>EDIT:</strong>
  I debugged this a little further and it seems that the event on Chrome does trigger the listeners, but keyCode/charCode is always 0. I've tried to set evt.keyCode or evt.charCode with no success either.</p>