Code document.onkeydown = handleDown; document.onkeyup = handleUp; document.onkeypress = handlePress; function handlePress(evt) { var thiskey = evt ? evt.which : window.event.keyCode; var e = document.getElementById('content'); e.innerHTML = e.innerHTML + "Key pressed: " + thiskey; } function handleUp(evt) { var thiskey = evt ? evt.which : window.event.keyCode; var e = document.getElementById('content'); e.innerHTML = e.innerHTML + "Key up: " + thiskey; } function handleDown(evt) { var thiskey = evt ? evt.which : window.event.keyCode; var e = document.getElementById('content'); e.innerHTML = e.innerHTML + "Key down: " + thiskey; }