KeyEvent which Property - Using onkeypress and onkeydown to demonstrate the differences between character codes and keyboard codes: - Javascript DOM

Javascript examples for DOM:Key Event

Description

KeyEvent which Property - Using onkeypress and onkeydown to demonstrate the differences between character codes and keyboard codes:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<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) {/*from   w  w  w.  j  a v a 2 s .  co m*/
    var char = event.which || event.keyCode;
    document.getElementById("demo").innerHTML = "The Unicode CHARACTER code is: " + char;
}

function uniKeyCode(event) {
    var key = event.which || event.keyCode;
    document.getElementById("demo2").innerHTML = "The Unicode KEY code is: " + key;
}
</script>

</body>
</html>

Related Tutorials