Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>Keyboard Events</h1>
<h2>The which Property</h2>
<p>Press any key on the keyboard in the input field to get the Unicode character code and the Unicode key code of the pressed key.</p>
<p><strong>Note:</strong> The which and keyCode property does not work on the onkeypress event for non-printable, function keys (like CAPS LOCK, CTRL, ESC, F12, etc.).</p>
<input type="text" size="50" onkeypress="uniCharCode(event)" onkeydown="uniKeyCode(event)"> 
<p>onkeypress - <span id="demo"></span></p>
<p>onkeydown - <span id="demo2"></span></p>
<script>
function uniCharCode(event) { 
  let char = event.which || event.keyCode; 
  document.getElementById("demo").innerHTML = "The Unicode CHARACTER code is: " + char;
}
function uniKeyCode(event) {
  let key = event.which || event.keyCode; 
  document.getElementById("demo2").innerHTML = "The Unicode KEY code is: " + key;
}
</script>
</body>
</html>