event.key property

The event.key property allows you to find out the value of a key pressed when entering text.

Syntax

javascriptevent.key;

Example

html<input id="elem">
javascriptlet elem = document.querySelector('#elem');

elem.addEventListener('keydown', function(event) {
  console.log(event.key);
});

See also

  • the event.altKey property
    that catches pressing the Alt key
  • the event.ctrlKey property
    that catches pressing the Ctrl key
  • the event.shiftKey property
    that catches pressing the Shift key
  • the event.metaKey property
    that catches pressing the Cmd key
  • the code property
    that obtains the code of a pressed key