<p>Please press any key.</p>UIEvent: which property / notebook
UIEvent: which property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
function showKeyPress(evt) {
console.log(
`onkeypress handler:\n` +
`keyCode property: ${evt.keyCode}\n` +
`which property: ${evt.which}\n` +
`charCode property: ${evt.charCode}\n` +
`Character Key Pressed: ${String.fromCharCode(evt.charCode)}\n`,
);
}
function keyDown(evt) {
console.log(
`onkeydown handler:\n` +
`keyCode property: ${evt.keyCode}\n` +
`which property: ${evt.which}\n`,
);
}
document.addEventListener("keypress", showKeyPress);
document.addEventListener("keydown", keyDown);