event.code property

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

Syntax

javascriptevent.code;

Example

Let's output the code of a pressed key to the console:

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

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

See also

  • the event.key property
    that obtains an entered character