Handle Key HIT/press event and check key code - Javascript DOM

Javascript examples for DOM:Key Event

Description

Handle Key HIT/press event and check key code

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*w  ww  . ja v a2 s.c  om*/
window.addEventListener('keypress', function(e) {
    e = e || window.event;
    switch(e.which) {
        case 77:
            if (e.ctrlKey) {
               console.log( "M + ctrlKey is down" );
               // do some here
            }
            else {
                console.log("M is down")
            }
        break;
    }
}, false);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials