title: How is document.createEvent supposed to work with key events?
body: <p>I am trying to simulate keypresses in a web application, it is for an embedded system but it uses a Webkit derived browser. I have tested the code in Chrome and get the same error.</p>
  
  <p>I tried to use code snippets from this example from <a href="http://developer.yahoo.com/yui/docs/UserAction.js.html" rel="nofollow noreferrer">Yahoo</a>, but I keep getting the same error when firing the event using <code>dispatchEvent</code>. "target" is an HTML element in the DOM tree.</p>
  
  <pre><code>function fireEvent(target) {
      var evt = document.createEvent("UIEvent");
      evt.initEvent("keypress", true, true);
      target.dispatchEvent(evt);
  }
  </code></pre>
  
  <p>It always throws:</p>
  
  <blockquote>
    <p>"Error: UNSPECIFIED_EVENT_TYPE_ERR: DOM Events Exception 0"</p>
  </blockquote>
  
  <p>I have tried <code>createEvent("Events")</code> as well and it always boils down to the same exception, both on the embedded system and in Chrome.</p>