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.
Below program illustrates the KeyboardEvent keyCode Property :
Example-1: Getting the Unicode value of a pressed keyboard key.
Before pressing a button:
After pressing a button:
- Internet Explorer
- Google Chrome
- Apple Safari
- HTML | DOM KeyboardEvent key Property
- HTML | KeyboardEvent which Property
- HTML | DOM keyboardEvent charCode Property
- HTML | DOM KeyboardEvent location Property
- HTML | DOM KeyboardEvent code Property
- HTML | DOM KeyboardEvent shiftKey Property
- HTML DOM | KeyboardEvent altKey Property
- HTML | DOM KeyboardEvent metaKey Property
- HTML | DOM KeyboardEvent
- HTML | DOM KeyboardEvent getModifierState() Method
- HTML | DOM value Property
- HTML | DOM li value Property
- HTML | DOM name Property
- HTML | DOM Bdo dir 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 firstname.lastname@example.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.