KeyboardEvent Value (keyCodes, metaKey, etc)

When a KeyboardEvent fires, you can test which key was pressed because that event contains information you can write logic against.

document.addEventListener("keydown", function(event) {
  console.log(event.which);
})

For example, by pressing “a”, you’ll get 65. Apparently it’s best to write …

Avatar of Chris Coyier
Chris Coyier on (Updated on )