Keyboard shortcut using JS / JQuery (Escape & Shift + Escape)

Is there a way in js / jquery how to use these two keyboard shortcuts?

ESCape Button and SHIFT + ESCape Key

when i implemented it using

    document.onkeydown = function(e){if (e == null) {keycode = event.keyCode;}
    else         {keycode = e.which;}
    if(keycode == 27){closeAll();}}

    //upon pressing shift + esc
    $(document).bind('keypress',function(event)
    {
          if(event.which === 27 && event.shiftKey)
        {
      closetogether();
       }

    });

the escape button works fine, but with shift + esc it gets confused, I think, because it does nothing. Do not worry that the function works when I change the key combination 27 to 90 (z), for example, it works fine.

Can someone choose me for a better way?

+3
source share
1 answer

keydown jQuery? , . shift .

. keyup/keydown keypress .

$(document).bind('keydown', function(event) {
    if(event.which === 27){
        if(event.shiftKey){
            closetogether();
        } else {
            closeAll();
        }
    }
});
+4

All Articles