james Oduro james Oduro - 4 months ago 22
Javascript Question

How to check if a type of keyboard key is press along with CTRL

I want to call functions if a particular key is press together with CTRL (windows system)

to test for a particular keyCode I used event.keyCode In this case I got to know the codes for each key. I assumed 17 + 73 will be CTRL + I

This doesn't seem to work except if I check of p only.

I want to be able to check for CTRL + a particular KEY.
Thank you.

What I tried:

//keyboard shorcut to call functions
$(document).on('keydown', function (e) {

if(e.keyCode === 90){ // I want CTL + I
//call image upload func...
return false;

}else if(e.keyCode === 97){ //I want CTL + P
return false;


 if(e.keyCode  === 90 && e.ctrlKey) {
 //   CTRL+I
 else if(e.keyCode  === 97 && e.ctrlKey){ 
   // CTRL + P 

This should work, check if e.ctrlKey is pressed.