EDIT: This code is not very good as it appeared. He will not see the difference between Ctrl + C and Cltrl + C + V !
Try this code:
var key = function (keys, fn) { $(document).on({ keydown: function (e) { var arr = []; if(e.ctrlKey) arr.push("17"); if(e.altKey) arr.push("18"); arr.push(e.which); if (arr.join(', ') === keys) { fn(e); } } }); };
Instead of collecting the keys pressed into a global array, you can check if it is pressed when the keydown event occurs. This works fine for me: http://fiddle.jshell.net/27WGw/2/ ( Note that I changed Ctrl + Alt + c to Ctrl + Alt + d since the first is a global hotkey on my machine)
source share