title: Chrome: Simulate keypress events on input text field using javascript
body: <p>There is a lot of contents on this in stack overflow but none seems to work for my case. I have an input text field and I want to simulate keypress event to fill the text field.</p>
  
  <p><strong>Reason:</strong> I am automating a lot of data entry task on a web interface which provides no API. Changing the input field using <code>.value</code> does not trigger the JS side (angular) of the interface. That is why I want to simulate keypress event.</p>
  
  <p>First I tried this:</p>
  
  <pre><code>var inp = document.getElementById('rule-type');
  inp.dispatchEvent(new KeyboardEvent('keypress',{'key':'a'}));
  </code></pre>
  
  <p>Then I learned in Chrome the <code>key</code> and <code>code</code> stays as 0 and does not change in <code>KeyBoardEvent</code>.</p>
  
  <p>So I created seperate event <code>ev = new KeyboardEvent('keypress',{'key':'a', 'code': 'KeyA'})</code></p>
  
  <p>And then I dispatched again, the return statement is <code>true</code> but it does not change the input field.</p>
  
  <p>The solution needs to be in pure javascript not jQuery.</p>