HTML | DOM keyboardEvent charCode Property
The keyboardEvent charCode property in HTML is used to return the unicode value of a character key pressed during a keypress event. It is a read-only property. The unicode character denotes the number of a character(e.g. the unicode for “A” is 65).
Syntax:
event.charCode
Return Value: It returns a number which represents the unicode number of the pressed character.
Example:
<html> <head> <title>keyboardEvent charCode Property</title> </head> <body style="text-align: center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h2> keyboardEvent charCode Property </h2> Input: <input type="text" placeholder="Press any key.."> <p id="p"></p> <script> // Adding a event listener function window.addEventListener("keypress", function(event) { var code = event.charCode; // Creating a span element var element = document.createElement("span"); element.innerHTML = "Unicode value: " + code + "<br/>"; // Appending span element to the paragraph document.getElementById("p").appendChild(element); }, true); </script> </body> </html> |
Output:

Supported Browsers: The browser supported by keyboardEvent charCode property are listed below:
- Apple Safari
- Google Chrome
- Firefox
- Opera
- Internet Explorer 9.0
Recommended Posts:
- HTML | KeyboardEvent which Property
- HTML | DOM KeyboardEvent key Property
- HTML | DOM KeyboardEvent metaKey Property
- HTML | DOM KeyboardEvent code Property
- HTML | DOM KeyboardEvent shiftKey Property
- HTML DOM | KeyboardEvent altKey Property
- HTML | DOM KeyboardEvent keyCode Property
- HTML | DOM KeyboardEvent location Property
- HTML | DOM KeyboardEvent
- HTML | DOM KeyboardEvent getModifierState() Method
- HTML | DOM URL Property
- HTML | DOM id Property
- HTML | DOM Bdo dir Property
- HTML | DOM li value Property
- HTML | DOM specified Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



