(ext.) KeyCode and CharCode

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.