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.altKeyproperty
that catches pressing the Alt key -
the
event.ctrlKeyproperty
that catches pressing the Ctrl key -
the
event.shiftKeyproperty
that catches pressing the Shift key -
the
event.metaKeyproperty
that catches pressing the Cmd key -
the
codeproperty
that obtains the code of a pressed key