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