<p>Type anything into the input box below to log a <code>charCode</code>.</p>
<input type="text" />
<p id="log"></p>KeyboardEvent: charCode property / notebook
KeyboardEvent: charCode property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const input = document.querySelector("input");
const log = document.querySelector("#log");
input.addEventListener("keypress", (e) => {
log.innerText = `Key pressed: ${String.fromCharCode(e.charCode)}\ncharCode: ${
e.charCode
}`;
});