How to listen for Ctrl-P key press in JavaScript?


I want to disable print for some webpages. How to wireup cross browser hotkeys (Cntrl + P) to a javascript that will be fired whenever hotkeys are pressed?

You can override by capturing the event.

jQuery(document).bind("keyup keydown", function(e){
    if(e.ctrlKey && e.keyCode == 80){
        return false;
    }
});

Also a great library is Mousetrap


Try Keyboard Shortcuts Library.

Instead of just copy pasting it let's havea look at the source and understand how it works.

You can see the source here