JSFiddle - React, Tailwind, and code Playground

HTML

<h1>KeyPress Example</h1>
<label for="keyInput">Key code (e.which):</label><input id="keyInput" type="text" readonly>
<p>Click anywhere inside this box and start tapping keys</p>

CSS

h1 {
    font-size: 1.2em;
    font-weight: bold;
    padding-bottom: 1em;
}
label + input {
    margin-left: 1em;
}
p {
    padding-top: 6em;
    text-align: center;
}

JavaScript

var input = document.getElementById("keyInput");

document.addEventListener("keypress", function(e) {
    input.value = e.which;
});