title: Keypress function not working in javascript
body: <p>I am trying to and have to <code>keypress</code> the letter 'A' with JavaScript.
  In the code below, there is an <code>alert('hello')</code> box that indicates that the code is executing.</p>
  
  <p>But this code doesn't set any values to the "login-email" input (which is a textbox).</p>
  
  <p>What can be wrong with the code?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>          function presskey()
            { 
                var e = document.createEvent('KeyboardEvent');
                if (e.initKeyboardEvent)
                {
                    alert('hello'); e.initKeyboardEvent('keypress', true, true, document.defaultView, 'A', 0, '', false, '');
                }
                document.getElementById('login-email').dispatchEvent(e);
            }</code></pre>
  </div>
  </div>
  </p>