JS Learning Note----keyboard events

Source: Internet
Author: User

There are 2 key keyboard events: onkeydown : triggered when the keyboard is pressed, if not lifted, it will be triggered continuously. onkeyup: When the keyboard bounces, not all elements can receive keyboard events, only elements that respond to user input, in other words, elements that receive focus can receive keyboard events.

Event.keycode : numeric type, which returns the ASCII code of the keyboard key. Ctrlkey, Shiftkey, Altkey: Boolean value. When an event occurs, if the ctrl| | Shift | | ALT is the pressed state, which returns true. Example code:
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3     <Head>4         <title>Keyboard events</title>5         <MetaCharSet= "UTF-8">6         <Metaname= "Viewport"content= "Width=device-width, initial-scale=1">7         <Script>8 window.onload= function(){9 Document.onkeydown= function(EV) {Ten                     varEV=EV||event; One                     //alert (Ev.keycode); Returns the ASCII code of the keyboard A                 } -  - Document.onclick= function(EV) { the                     varEV=EV||event; - alert (ev.ctrlkey);//returns False when clicked, and returns True when the CTRL key is pressed and then clicked -                 } -             }                   +         </Script> -     </Head> +     <Body> A         <Div> at              -         </Div> -     </Body> - </HTML>

JS Learning Note----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.