0

I need to detect which keys are pressed in keyboard to do some action upon that
so I wrote script like this

$(document).keyup(function(e){  
   var map = {18: false, 17: false, 65: false};
   if (e.keyCode in map) {
     map[e.keyCode] = true;
     if (map[18] && map[17] && map[65]) {
        alert("Pressed Alt+Ctrl+a");
     }
   }
});  

but this script doesn't work
so can any on help me in this please

Mohamed Salah
  • 156
  • 1
  • 15
  • See also [Detect keypress combination series with Javascript](http://stackoverflow.com/questions/10061084/detect-keypress-combination-series-with-javascript). – Zakaria Acharki Jul 14 '15 at 12:53
  • You could also use `Set` like so `var keyPress=new Set();$(document).keydown(function(e){ keyPress.add(e.keyCode);if (keyPress.has(18)&&keyPress.has(17)&&keyPress.has(65)) {alert("Pressed Alt+Ctrl+a"); }}); $(document).keyup(function(e){ keyPress.delete(e.keyCode);});` – depperm Jul 14 '15 at 13:00

1 Answers1

1

the e object will provide e.ctrlKey aswell as e.altKey and e.shiftKey

you just need to test for this: e.ctrlKey && e.altKey && e.which == 65

GottZ
  • 4,824
  • 1
  • 36
  • 46