Keyboard events have two properties, KeyCode and CharCode, and there are a few differences between them. KeyCode indicates that the user presses the actual encoding of the key, while CharCode refers to the encoding of the user by pressing the character.
ie underKeyCode: For the KeyPress event, the Unicode character that presses the key, or the numeric code that presses the key for the Keydown/keyup event.No CharCode property.
DOM StandardKeyCode: The numeric code that represents the press of the key. CharCode: Press the Unicode character of the key. When I press the "
a"Key (note that the
lowercaseLetters), in Firefox you will get Keydown:keycode is CharCode are 0keypress:keycode is 0 CharCode are 97keyup:keycode is the charcode is 0 in Google will get Keydown:keycode is CharCode are 0keypress:keycode is the charcode is the 97keyup:keycode is a + charcode is 0 in IE Will be Keydown:keycode is CharCode are Undefinedkeypress:keycode is the charcode is Undefinedkeyup:keycode E is undefined and when I pressShiftKey, in Firefox will get Keydown:keycode is CharCode are 0keyup:keycode is the charcode is 0 will not get any charcode value, because press SHIFT does not enter any characters, and also does not The KeyPress event is triggered. In Google will get Keydown:keycode is CharCode are 0keyup:keycode is the charcode is 0 in IE will get Keydown:keycode is more charcode is Undefinedkeyup:keycode is charcode undefined
Summary:1. In the KeyDown event, the event contains the physical encoding of the button pressed by the keycode– user. 2. In KeyPress, KeyCode contains the character encoding, which is the ASCII code that represents the character. This form applies to all browsers – in addition to Firefox, its keycode return value in the KeyPress event is 0. If you want to get the button that the user is actually tapping, use the KeyDown event to get the event object and get the KeyCode value, which will work across all browsers. On the other hand, if you want to get the characters entered by the user, then use KeyPress to get them, then get CharCode (Firefox and Safari) or KeyCode (other browsers).
(ext.) KeyCode and CharCode