offline version v3


226 of 264 menu

event.key property

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

Syntax

event.key;

Example

<input id="elem"> let 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
enru