0

How to trigger key-press of ctrl+ shift+m in jQuery?

I tried the below code for single key.Its working.But i want to trigger all the three keys at the same time.

$(document).on('keypress', function(e) {
  alert(String.fromCharCode(e.keyCode));
});

$(document).trigger(jQuery.Event('keypress', { which: 77 }));
$(document).trigger(jQuery.Event('keypress', {
  which: 77, 
  keyCode: 77 
}));
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • 1
    Simple answer: *don't*. Place the logic in a function and call it from the normal keypress handler, and any location you're trying to run your `trigger()` call. Triggering key-based events is inconsistent at best – Rory McCrossan Jul 03 '17 at 07:26

1 Answers1

0

you can control it with the code above

if ( e.ctrlKey && e.shiftKey && ( e.which === 77 ) ) {
    console.log( "You pressed CTRL + Shift + m" );
}

Hope it helps!! :)