Skip to content

charcode in JavaScript | Get Unicode character of the key on the keyboard

  • by

e.charCode – a number that represents the Unicode character of the key on the keyboard. The charCode is a property, which returns the Unicode character code of the key that triggered the onkeypress event.

Example charcode in JavaScript

Press a key on the keyboard in the input field to get the Unicode character code of the pressed key.

<!DOCTYPE html>

  <input type="text" size="40" onkeypress="myFunction(event)">

  <p id="res"></p>

    function myFunction(event) {
      var x = event.charCode;
      document.getElementById("res").innerHTML = x;



charcode in JavaScript  Unicode character key keyboard

Do comment if you have any doubts or suggestions on this JS code.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.