Amit Dhamu

Writes Code

Implement Keyboard Shortcuts For Your Website

$(document).ready(function() {
 // I have used $(this) so it "listens" on any part of the webpage (document)
    // Change this to a single or series of elements if required
  $(this).live("keyup", function(e) {
     if($("input, textarea").is(":focus")) {
           // Do nothing because the user might be typing
            return false;
     } else {
          switch(e.keyCode) {

             case 65:  
                    // Do something here when I press the A key
                   break;

              case 69:  
                    // Do something here when I press the E key
                   break;

              // etc......
          }
     }
 });
});


For a list of JavaScript keycodes, you can visit this website.


keyboard / shortcuts / keycode / jquery

← Favicon For Windows 8 Tile Pure CSS Speech Bubble →