JavaScript Event Object _ keyboard Event

Source: Internet
Author: User

The keyboard event is triggered when the user is using the keyboard. The "DOM2 level event" initially defined the keyboard event, and the result was deleted. The initial keyboard event is still used, but IE9 has been the first to support "DOM3"-level keyboard events.

One, key code

  When the KeyDown and KeyUp events occur, the KeyCode property of the event object contains a code that corresponds to a specific key on the keyboard. For the alphanumeric character set, the value of the KeyCode property is the same as the encoding of the corresponding lowercase letter or number in the ASCII code. The capitalization of the letters does not affect.

<script type= "Text/javascript" >    function() {        function  (EVT) {            // Press any key to get the corresponding keycode        };    }; </script>

Different browsers in the KeyDown and KeyUp events, there will be some special cases: in Firefox and Opera, the semicolon key keycode value is 59, which is the ASCII semicolon encoding, and IE and Safari return 186, that is, the key keys in the keyboard Code.

<script type= "Text/javascript" >    function() {        function  (EVT) {            // Press any key to get the corresponding keycode        };    }; </script>

If you return keycode with KeyPress, all the character keys in Firefox return 0, not the character key does not respond. Chrome,ie supports KeyPress return keycode, and also supports case

Second, character encoding

The event objects for Firefox, Chrome, and Safari all support a CharCode property that contains the value only when the KeyPress event occurs, and that the value is the ASCII encoding of the character represented by the pressed key.

At this point the keycode is usually equal to 0 or it may be equal to the key code. IE and Opera are ASCII-encoded characters that are stored in keycode.

<script type= "Text/javascript" >    function() {        function  (EVT) {            alert (evt.charcode);          // Press any key to get the corresponding character encoding         };    }; </script>

JavaScript Event Object _ keyboard Event

Related Article

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.