title: Firing a Keyboard Event in Safari, using JavaScript
body: <p>I'm trying to simulate a keyboard event in Safari using JavaScript.</p>
  
  <p>I have tried this:</p>
  
  <pre><code>var event = document.createEvent("KeyboardEvent");
  event.initKeyboardEvent("keypress", true, true, null, false, false, false, false, 115, 0);
  </code></pre>
  
  <p>...and also this:</p>
  
  <pre><code>var event = document.createEvent("UIEvents");
  event.initUIEvent("keypress", true, true, window, 1);
  event.keyCode = 115;
  </code></pre>
  
  <p>After trying both approaches, however, I have the same problem: after the code has been executed, the <code>keyCode</code>/<code>which</code> properties of the event object are set to <code>0</code>, not <code>115</code>.</p>
  
  <p>Does anyone know how to reliably create and dispatch a keyboard event in Safari? (I'd prefer to achieve it in plain JavaScript if possible.)</p>