title: KeyboardEvent in Chrome, keyCode is 0
body: <p>I am trying to set keyCode on dispatched event object .</p>
  
  <p>On button click, event is raised on textbox control to simulating keydown event. Event is raised successfully, but keyCode is 0. I need to send event object with correct keyCode to textbox.
  I've been using code from <a href="https://stackoverflow.com/questions/4158847/is-there-a-way-to-simulate-key-presses-or-a-click-with-javascript">here</a>.</p>
  
  <p>How to set keyCode value in dispatched event?</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;      
      &lt;/head&gt;
      &lt;body&gt;
          &lt;input type="button" id="btn" value="Click"&gt;&lt;/input&gt;
          &lt;input type="text" id="txt"&gt;&lt;/input&gt;
          &lt;script&gt;
              document.getElementById('btn').addEventListener("click", btnClick);
              document.getElementById('txt').addEventListener("keydown", txtKeydown);         
  
              function btnClick(e) {
                  var txt = document.getElementById('txt');               
  
                  var dispatchKeyboardEvent = function(target, initKeyboradEvent_args) {
                      var e = document.createEvent("KeyboardEvents");
                      e.initKeyboardEvent.apply(e, Array.prototype.slice.call(arguments, 1));
                      e.keyCode = 83;
                      e.charCode = 0;
                      target.dispatchEvent(e);
                  };
  
                  var canceled = !dispatchKeyboardEvent(txt,
                  'keydown', true, true,  // type, bubbles, cancelable
                  window,  // window
                  's',  // key
                  0, // location: 0=standard, 1=left, 2=right, 3=numpad, 4=mobile, 5=joystick
                  false, false, false);  // Ctr, Alt, Shift
              }
  
              function txtKeydown(e) {
                  console.dir(e);
                  console.log(e.keyCode);
              }
  
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>