Examples of JS keyboard events

Source: Internet
Author: User

JavaScript onkeydown Events

The onkeydown event is triggered when a user presses a keyboard key. Unlike the onkeypress event, the onkeydown event responds to any key-pressed processing (including function keys), and the onkeypress event responds only to the processing of the character key as it is pressed.

Tips

The Internet Explorer/chrome Browser uses Event.keycode to retrieve the characters that are pressed, while browsers such as Netscape/firefox/opera use Event.which.

OnKeyDown gets the key that the user pressed

Here is an example of using the onkeydown event to get the user to press the keyboard key information:

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "UTF-8">        <title>Keyboard events</title>    </Head>    <Body>        <inputtype= "text"onkeydown= "Return Nonumbers (event)" />        <Scripttype= "Text/javascript">            functionNonumbers (e) {varKeynum; varKeychar; Keynum=window.event?E.keycode:e.which; Keychar=String.fromCharCode (Keynum); Alert (Keynum+':'+Keychar); }//document.onkeyup = function () {//alert (' Keyboard pop Up ');//            };//Document.onkeydown = function () {//alert (' keyboard pressed ');//            };//document.onkeypress = function () {//alert (' Keyboard hold ');//            }        </Script>    </Body></HTML>
JS inside the keyboard events are often used, so the collection of keyboard events corresponding to the key code to share the following:
KeyCode 8 = BackSpace Backspacekeycode 9 = Tab Tabkeycode = Clearkeycode = Enterkeycode = Shift_lkeycode + = Con Trol_lkeycode = Alt_lkeycode = Pausekeycode = Caps_lockkeycode = Escape Escapekeycode + = Spacekeycode = P Riorkeycode = Nextkeycode = Endkeycode = Homekeycode PNs = Leftkeycode = Upkeycode = Rightkeycode = Downk Eycode = Selectkeycode = Printkeycode = Executekeycode = Insertkeycode = Deletekeycode 48 = Helpkeycode = 0 Equal Bracerightkeycode = 1 Exclam onesuperiorkeycode = 2 Quotedbl twosuperiorkeycode Wuyi = 3 section Threesuperi Orkeycode = 4 Dollarkeycode = 5 Percentkeycode = 6 Ampersandkeycode = 7 Slash Braceleftkeycode 8 Parenlef  T Bracketleftkeycode = 9 Parenright Bracketrightkeycode = a Akeycode (= b bkeycode) = c Ckeycode = d Dkeycode Eurosignkeycode = e E = f Fkeycode = g Gkeycode = h Hkeycode = i ikeycode = J Jkeycode = k Kkeycode Lkeycode = L = m m Mukeycode = n Nkeycode = o okeycode = p Pkeycode bayi = q Q atkeycode = R Rkeycode = s Skeycode = t TKEYC Ode = u Ukeycode = v Vkeycode xkeycode = w wkeycode (x ykeycode) = y Zkeycode = z kp_0  Kp_1 = Kp_1keycode 98 = kp_2 Kp_2keycode = kp_3 Kp_3keycode = kp_4 Kp_4keycode 101 = kp_5 Kp_5keycode 102 = KP_6  Kp_6keycode 103 = kp_7 Kp_7keycode 104 = kp_8 Kp_8keycode = kp_9 Kp_9keycode 106 = kp_multiply KP_MultiplykeyCode 107 = Kp_add Kp_addkeycode 108 = kp_separator Kp_separatorkeycode 109 = kp_subtract Kp_subtractkeycode = KP_Decimal KP_De Cimalkeycode 111 = kp_divide Kp_dividekeycode, f1keycode 113 = F2keycode = F3keycode, = F4keycode = F5keyC  Ode 117 = F6keycode 118 = F7keycode 119 = F8keycode = F9keycode 121 = F10keycode 122 = F11keycode 123 = F12keycode 124 = F13keycode = F14keycode 126 = F15keycode 127 = F16keycode = F17keycode 129 = F18keycode = F19keycode 131 = F20keycode = F21KEYCOde 133 = F22keycode 134 = F23keycode 135 = F24keycode 136 = Num_lockkeycode 137 = Scroll_lockkeycode 187 = Acute Gravekey Code 188 = comma Semicolonkeycode 189 = minus Underscorekeycode = period Colonkeycode 192 = Numbersign Apostrophekeyco De Plusminus = hyphen Macronkeycode 211 =keycode 212 = Copyright Registeredkeycode 213 = Guillemotleft GUILLEMOTRIGHTK Eycode 214 = masculine Ordfemininekeycode 215 = ae Aekeycode 216 = cent Yenkeycode 217 = Questiondown ExclamdownkeyCode 21 8 = onequarter Onehalf Threequarterskeycode = Less greater barkeycode 221 = plus asterisk Asciitildekeycode 227 = mult iply Divisionkeycode 228 = Acircumflex Acircumflexkeycode 229 = Ecircumflex Ecircumflexkeycode = Icircumflex ICIRCUMFL Exkeycode 231 = Ocircumflex Ocircumflexkeycode 232 = Ucircumflex Ucircumflexkeycode 233 = Ntilde NtildekeyCode 234 = yacut E yacutekeycode 235 = oslash Oobliquekeycode 236 = aring Aringkeycode 237 = Ccedilla Ccedillakeycode 238 = Thorn THORNkeyC Ode 239 = ETH Ethkeycode diaeresis cedilla currencykeycode 241 = agrave Agrave atilde atildekeycode 242 = egrave Egravekeycode 243 = Igrave  Igravekeycode 244 = ograve Ograve Otilde otildekeycode 245 = ugrave Ugravekeycode 246 = adiaeresis AdiaeresiskeyCode 247 = Ediaeresis Ediaeresiskeycode 248 = idiaeresis Idiaeresiskeycode 249 = odiaeresis Odiaeresiskeycode = udiaeresis Udiae Resiskeycode 251 = ssharp question Backslashkeycode 252 = asciicircum Degreekeycode 253 = 3 Sterlingkeycode 254 = Mode_swi TCH uses the KeyCode property of the event object to determine the input key value eg:if (event.keycode==13) alert ("enter!"); Key value corresponds to table a 0X65 U 0x85b 0X66 V 0x86c 0X67 W 0x87d 0X68 X 0x88e 0X69 Y 0x89f 0X70 Z 0x90g 0X71 0 0X   48H 0X72 1 0x49i 0x73 2 0x50j 0X74 3 0x51k 0x75 4 0x52l 0X76 5 0x53m 0X77 6 0x54n 0X78 7 0x55o 0X79 8 0x56p 0X80 9 0x57q 0X81 ESC 0x1br 0X82 CTRL 0x11s 0X83 SHIFT 0x10t 0X84 ENTER 0XD
If 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

Examples of JS keyboard events

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.