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