Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 411
John Avatar asked Sep 20 '12 17:09

John


People also ask

How do you get if a key is pressed in JavaScript?

In plain JavaScript, you can use the EventTarget. addEventListener() method to listen for keyup event. When it occurs, check the keyCode 's value to see if an Enter key is pressed.

How do you implement Ctrl Z in JavaScript?

To capture ctrl+z key combination in JavaScript, we can listen to the keydown event. document. addEventListener("keydown", (event) => { if (event. ctrlKey && event.

What is key down in JavaScript?

The keydown event occurs when a keyboard key is pressed down. The keydown() method triggers the keydown event, or attaches a function to run when a keydown event occurs. Tip: Use the event. which property to return which keyboard key was pressed.


1 Answers

You can override by capturing the event.

jQuery(document).bind("keyup keydown", function(e){     if(e.ctrlKey && e.keyCode == 80){         return false;     } }); 
like image 181
Anoop Avatar answered Oct 03 '22 21:10

Anoop