Get keyboard events in JS

Source: Internet
Author: User

1<script type= "Text/javascript" Language=javascript charset= "UTF-8" >2document.onkeydown=function(event) {3             varE = Event | | window.event | | Arguments.callee.caller.arguments[0];4             if(e && e.keycode==27) {//Press ESC5                 //the things to do6               }7             if(e && e.keycode==113) {//Press F28                  //the things to do9                }            Ten              if(e && e.keycode==13) {//Enter key One                  //the things to do A             } -         };  -</script> theAs long as you define the actions of these keys, you can press these keys in the browser to respond, compatible with all current browsers.
1 JS inside the keyboard events are often used, so the collection of keyboard events corresponding to the key code to share the following:2KeyCode 8 =BackSpace BackSpace3KeyCode 9 =tab TAB4KeyCode 12 =Clear5KeyCode 13 =Enter6KeyCode 16 =shift_l7KeyCode 17 =control_l8KeyCode 18 =alt_l9KeyCode 19 =PauseTenKeyCode 20 =Caps_lock OneKeyCode 27 =Escape Escape AKeyCode 32 =Space -KeyCode 33 =Prior -KeyCode 34 =Next theKeyCode 35 =End -KeyCode 36 =Home -KeyCode 37 = Left -KeyCode 38 = up +KeyCode 39 = Right -KeyCode 40 = Down +KeyCode 41 =Select AKeyCode 42 =Print atKeyCode 43 =Execute -KeyCode 45 =Insert -KeyCode 46 =Delete -KeyCode 47 = Help -KeyCode 48 = 0equal Braceright -KeyCode 49 = 1Exclam Onesuperior inKeyCode 50 = 2Quotedbl Twosuperior -KeyCode 51 = 3Section Threesuperior toKeyCode 52 = 4Dollar +KeyCode 53 = 5percent -KeyCode 54 = 6Ampersand theKeyCode 55 = 7Slash Braceleft *KeyCode 56 = 8Parenleft Bracketleft $KeyCode 57 = 9parenright bracketrightPanax NotoginsengKeyCode 65 =a A -KeyCode 66 =b b theKeyCode 67 =C c +KeyCode 68 =D D AKeyCode 69 =e e eurosign theKeyCode 70 =F F +KeyCode 71 =G G -KeyCode 72 =H H $KeyCode 73 =I i $KeyCode 74 =J J -KeyCode 75 =k K -KeyCode 76 =l l theKeyCode 77 =m M Mu -KeyCode 78 =N NWuyiKeyCode 79 =o o theKeyCode 80 =P P -KeyCode 81 =q q at WuKeyCode 82 =R R -KeyCode 83 =s S AboutKeyCode 84 =T T $KeyCode 85 =u u -KeyCode 86 =v v -KeyCode 87 =W W -KeyCode 88 =x x AKeyCode 89 =y y +KeyCode 90 =Z z theKeyCode 96 =kp_0 kp_0 -KeyCode 97 =kp_1 kp_1 $KeyCode 98 =kp_2 kp_2 theKeyCode 99 =kp_3 kp_3 theKeyCode 100 =kp_4 Kp_4 theKeyCode 101 =kp_5 kp_5 theKeyCode 102 =kp_6 kp_6 -KeyCode 103 =kp_7 kp_7 inKeyCode 104 =kp_8 kp_8 theKeyCode 105 =Kp_9 Kp_9 theKeyCode 106 =kp_multiply kp_multiply AboutKeyCode 107 =Kp_add Kp_add theKeyCode 108 =Kp_separator Kp_separator theKeyCode 109 =kp_subtract kp_subtract theKeyCode 110 =Kp_decimal Kp_decimal +KeyCode 111 =kp_divide kp_divide -KeyCode 112 =F1 theKeyCode 113 =F2BayiKeyCode 114 =F3 theKeyCode 115 =F4 theKeyCode 116 =F5 -KeyCode 117 =F6 -KeyCode 118 =F7 theKeyCode 119 =F8 theKeyCode 120 =F9 theKeyCode 121 =F10 theKeyCode 122 =F11 -KeyCode 123 =F12 theKeyCode 124 =F13 theKeyCode 125 =F14 theKeyCode 126 =F1594KeyCode 127 =F16 theKeyCode 128 =F17 theKeyCode 129 =F18 theKeyCode 130 =F1998KeyCode 131 =F20 AboutKeyCode 132 =F21 -KeyCode 133 =F22101KeyCode 134 =F23102KeyCode 135 =F24103KeyCode 136 =Num_lock104KeyCode 137 =Scroll_lock theKeyCode 187 =Acute grave106KeyCode 188 =Comma semicolon107KeyCode 189 =minus underscore108KeyCode 190 =Period Colon109KeyCode 192 =numbersign Apostrophe theKeyCode 210 =Plusminus hyphen Macron111KeyCode 211 = theKeyCode 212 =Copyright Registered113KeyCode 213 =Guillemotleft guillemotright theKeyCode 214 =masculine Ordfeminine theKeyCode 215 =AE AE theKeyCode 216 =cent Yen117KeyCode 217 =Questiondown Exclamdown118KeyCode 218 =onequarter onehalf threequarters119KeyCode 220 =Less Greater bar -KeyCode 221 =plus asterisk Asciitilde121KeyCode 227 =Multiply Division122KeyCode 228 =Acircumflex Acircumflex123KeyCode 229 =Ecircumflex Ecircumflex124KeyCode 230 =Icircumflex Icircumflex theKeyCode 231 =Ocircumflex Ocircumflex126KeyCode 232 =Ucircumflex Ucircumflex127KeyCode 233 =Ntilde Ntilde -KeyCode 234 =Yacute Yacute129KeyCode 235 =Oslash Ooblique theKeyCode 236 =aring aring131KeyCode 237 =Ccedilla Ccedilla theKeyCode 238 =Thorn Thorn133KeyCode 239 =ETH ETH134KeyCode 240 =diaeresis cedilla Currency135KeyCode 241 =agrave agrave Atilde Atilde136KeyCode 242 =Egrave Egrave137KeyCode 243 =Igrave Igrave138KeyCode 244 =ograve ograve Otilde Otilde139KeyCode 245 =Ugrave Ugrave $KeyCode 246 =adiaeresis adiaeresis141KeyCode 247 =ediaeresis ediaeresis142KeyCode 248 =idiaeresis idiaeresis143KeyCode 249 =odiaeresis odiaeresis144KeyCode 250 =udiaeresis udiaeresis145KeyCode 251 =ssharp question Backslash146KeyCode 252 =Asciicircum degree147KeyCode 253 = 3Sterling148KeyCode 254 =Mode_switch149 Use the KeyCode property of the event object to determine the input key value Maxegif(event.keycode==13) alert ("enter!");151 Key-value correspondence table theA 0X65 U 0X85153B 0X66 V 0X86154C 0X67 W 0X87155D 0X68 X 0X88156E 0X69 Y 0X89157F 0X70 Z 0X90158G 0X71 0 0X48159H 0X72 1 0X49 theI 0x73 2 0X50161J 0X74 3 0X51162K 0x75 4 0X52163L 0X76 5 0X53164M 0X77 6 0X54165N 0X78 7 0X55166O 0X79 8 0X56167P 0X80 9 0X57168Q 0X81 ESC 0X1B169R 0X82 CTRL 0X11 theS 0X83 SHIFT 0X10171T 0X84 ENTER 0XD172If you want to use a combination of keys, you can determine whether the keys are pressed at the same time, such as CTRL, SHIFT, and the combination of the ALT key to determine whether to press the CTRL key, the SHIFT key and the ALT key

Thanks to the internet for the Great gods.

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.