1

I have taken this reference code from Detect multiple keys on single keypress event in jQuery

Here in this reference it is mention one event of pressing multiple keys, I have added one more event, but I am facing problem, that is when I am trying to call the second event by pressing its keys, the previous event is triggered just after pressing first key of that scenario/event (though i am unable to press all the multiple keys of second event) Can anybody tell me how to resolve this issue?

var ctr_b_g_map = {17: false, 66: false, 71: false};
var ctr_q_b_map = {17: false, 81: false, 66: false};
$(document).keydown(function(e) {
if (e.keyCode in ctr_b_g_map) {
    ctr_b_g_map[e.keyCode] = true;
    if (ctr_b_g_map[17] && ctr_b_g_map[66] && ctr_b_g_map[71]) {
        alert("Ctrl + b + g shortcut combination was pressed by JEQUERY");
    }
}//end of if inside keydown
else if (e.keyCode in ctr_q_b_map) {
    ctr_q_b_map[e.keyCode] = true;
    if (ctr_q_b_map[17] && ctr_q_b_map[81] && ctr_q_b_map[66]) {
        alert("Ctrl + q + b shortcut combination was pressed by JEQUERY");
    }
}

}).keyup(function(e) {
    if (e.keyCode in ctr_b_g_map) {
        ctr_b_g_map[e.keyCode] = false;
    }
   else if (e.keyCode in ctr_q_b_map) {
    ctr_q_b_map[e.keyCode] = false;
}
});

0 Answers0