How to detect the browser keydown event with javascript?

Here is how you can detect the browser keydown event and saved that keycode to an array.

//record keyevents
document.onkeydown = function(e){
  e = e?e:window.event;
  keyPressList[e.keyCode] = true;
};

We use the document’s onkeydown listener to listen for the keydown event on our web browser with the above code.