Commonly used keyboard events

1.keyup button that pops up when the trigger

 document.onkeyup = function(){

   console.log ( 'I bounced');

 }

2.keydown triggered when the button is pressed to identify a function key such as Ctrl shift left or right arrow

 document.addEventListener('keydown',function(){

   console.log ( 'I pressed down');

 })

3.keypress key is pressed when the trigger does not recognize the function keys such as Ctrl shift left or right arrow

 document.addEventListener('keypress',function(){

   console.log ( 'I pressed the keypress');

 })

4. The order of execution of three events: keydown - - keypress - - keyup

The keyboard event object keyCode returns the ASCII value of the key

6.keydown keyup - insensitive and case-sensitive keypress

 document.addEventListener('keydown',function(e){

   if( e.keyCode === 65 ){

     alert ( "pressed a key");

   }else{

     alert ( 'not pressed a button');

   }

 })

Guess you like

Origin www.cnblogs.com/qtbb/p/11688699.html