KeyCode ()
The KeyCode property returns the code for the character of the value of the onkeypress event-triggered key, or for the key of the onkeydown or onkeyup event.
The differences between the two types of code are:
- character code-a number that represents ASCII characters
- keyboard code-a number that represents a real key on the keyboard
P> Two types of values are not equal, such as lowercase characters "w" and uppercase characters "W" have the same keyboard code, because they are on their keyboard ("W" Code is "87"), but they have different character codes, two character output is not the same ("W" and "W" character code is "119" and "87")-View the following examples to better understand.
Tip: If you need to know that the user is pressing a print key (such as "a" or "5"), we recommend that you use the onkeypress event. If you need to know that the user is pressing a function key (such as "F1", "CAPS LOCK" or "Home") you can use the onkeydown or onkeyup event.
Note: in Firefox, the KeyCode property is not valid in the onkeypress event (returns 0). Browser compatibility issues that you can use together with the which and KeyCode properties to resolve:
var x = Event.which | | Event.keycode; Use
whichOr
KeyCode, which supports different browsers
Tip: List of all Unicode characters to view our full Unicode reference manual.
Tip: If you need to convert Unicode values to characters, you can use the fromCharCode () method.
Note: This property is read-only.
Note: the which and KeyCode properties provide a way to resolve browser compatibility, and the latest version of DOM events is recommended to replace this method with the key property.
Tip: If you want to see if "ALT", "CTRL", "META" or "SHIFT" keys are pressed, you can use Altkey, Ctrlkey, Metakey, or Shiftkey properties.
RELATED LINKS
The use of keycode in JavaScript