Javascript KeyChar, KeyCode

How To Use Key Char And Key Code In JS

js keycode & keychar


In this JavaScript tutorial, we will explore how to utilize charCode and keyCode on both key press and key down events. With JavaScript programming language and NetBeans editor, you have the ability to easily check the specific key that has been pressed, offering a greater level of control and functionality.


Project Source Code:


<!DOCTYPE html>
<html>
    <head>
        <title>JavaScript: Key Code - Char Code</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body onkeypress="listenKey(event)">
        <script>
            
            function listenKey(event)
            {
                var cd = event.keyCode, ch = event.charCode,val = String.fromCharCode(ch);
                console.log("keyCode = "+cd+" charCode = "+ch + " Value = "+ val);
            }
            
        </script>
    </body>
</html>


Share this

Related Posts

Previous
Next Post »