Javascript keyboard Events

Source: Internet
Author: User

Window.document.onkeydown =function (e) {varevt = window.Event|| E//Compatibility processing            varKeyCode =Evt.keycode; Switch(keycode) { Case Panax Notoginseng://leftpgwslideshow.previousslide ();  Break;  Case  the://Rightpgwslideshow.nextslide ();  Break;                  }                }; 

Keyboard events for JavaScript

KeyCode 37 is left ARROW key, 38 is upper, 39 is right, 40 is lower

Phase key values can be referenced http://www.cnblogs.com/hsapphire/archive/2009/12/16/1625642.html

-------------------------------------------------Split Line-----------------------------------------------------

Refer to some of the http://www.jb51.net/article/44654.htm in the following section:

Document.onkeyup =functionvar currkey=0,e=e| |      event; Currkey=e.keycode| | e.which| |      E.charcode;       var keyName = String.fromCharCode (currkey); Console.log ("Key code:" + Currkey + "character:" + keyName);  

The above method is quite ingenious and simply explains:
First, e=e| | This code is intended for compatibility with browser event object acquisition. JS in this code means, if in Firefox or opera, the hidden variable e is present, then e| | Event returns E, if the hidden variable e is not present in IE, the event is returned.
Second, currkey=e.keycode| | e.which| | E.charcode; This is to be compatible with the key properties of the browser key event object (see the third part), IE, only the keycode attribute, and Firefox has which and CharCode properties, Opera has KeyCode and which properties.

Javascript keyboard Events

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.