Open In App
Related Articles

HTML | DOM KeyboardEvent keyCode Property

Improve Article
Save Article
Like Article

The KeyboardEvent keyCode property is used for returning the Unicode character code of the key that has been used to trigger an onkeypress event. The KeyboardEvent keyCode property is also used for returning the Unicode character code of a key that has triggered an onkeydown or onkeyup event. The key codes represent an actual key on the keyboard whereas character codes represent an ASCII character. Upper case and lower case characters have different codes. 



Note: This property has been DEPRECATED and is no longer recommended.

Below program illustrates the KeyboardEvent keyCode Property : 

Example-1: Getting the Unicode value of a pressed keyboard key. 


<!DOCTYPE html>
    <title>KeyboardEvent keyCode Property in HTML
        div {
            border: 3px solid green;
            height: 100px;
            width: 500px;
        h1 {
            color: green;
        h2 {
            font-family: Impact;
        body {
            text-align: center;
    <h2>KeyboardEvent keyCode Property</h2>
    <p>To return the keycode of a key,
      insert some character in the field.</p>
    <input type="text"
    <p id="test"></p>
        function keyboard(event) {
            //  Return key code.
            var k = event.which || event.keyCode;
            document.getElementById("test").innerHTML =
              "The keycode value of the pressed key is : " + k;


Before pressing a button:


After pressing a button:


Supported Browsers:

  • Opera
  • Internet Explorer
  • Google Chrome
  • Firefox
  • Apple Safari

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 06 Jul, 2022
Like Article
Save Article
Similar Reads
Related Tutorials