onlyforbopi
9/19/2018 - 7:18 PM

JS.Events.KeyupKeyDownEvent

JS.Events.KeyupKeyDownEvent

window.onkeypress = processKeyPress;

/* or we could have written:
   window.addEventListener('keypress', processKeyPress);
*/

function processKeyPress(evt) {
  var keys = document.querySelector('#keys');
  keys.innerHTML += "keypress: " + evt.key + " code: " + evt.keyCode + "<br>";
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Example of the 'keypress' event on the window object</title>
</head>
  <body>
    <p>Please type some keys and see what happens. Notice that the event fired only once you pressed a key down and released it (only one event per keypress)</p>
    <div id="keys"></div>
  </body>
</html>