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