shortcut key not working ctrl + shift + numpad1











up vote
0
down vote

favorite












I need to implement a simple functionality on keyboard shortcut but combination with 'shift' key not work :( .



 window.onkeydown = (event) => {
if (event.ctrlKey && event.shiftKey) {
switch (event.key) {
case '1':
// something
break;
}
}
}









share|improve this question






















  • shift+numpad1 isn't a number, it's an End key...
    – Chayim Friedman
    Nov 19 at 12:13










  • shift+1 is also !
    – 0.sh
    Nov 19 at 12:14










  • how to make this combination work ? ctrl+shif+numpad1
    – Filip Laurentiu
    Nov 19 at 12:16










  • Possible duplicate of How to detect if multiple keys are pressed at once using JavaScript?
    – Ram Segev
    Nov 19 at 12:17










  • Check this
    – Zohir Salak
    Nov 19 at 19:52

















up vote
0
down vote

favorite












I need to implement a simple functionality on keyboard shortcut but combination with 'shift' key not work :( .



 window.onkeydown = (event) => {
if (event.ctrlKey && event.shiftKey) {
switch (event.key) {
case '1':
// something
break;
}
}
}









share|improve this question






















  • shift+numpad1 isn't a number, it's an End key...
    – Chayim Friedman
    Nov 19 at 12:13










  • shift+1 is also !
    – 0.sh
    Nov 19 at 12:14










  • how to make this combination work ? ctrl+shif+numpad1
    – Filip Laurentiu
    Nov 19 at 12:16










  • Possible duplicate of How to detect if multiple keys are pressed at once using JavaScript?
    – Ram Segev
    Nov 19 at 12:17










  • Check this
    – Zohir Salak
    Nov 19 at 19:52















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I need to implement a simple functionality on keyboard shortcut but combination with 'shift' key not work :( .



 window.onkeydown = (event) => {
if (event.ctrlKey && event.shiftKey) {
switch (event.key) {
case '1':
// something
break;
}
}
}









share|improve this question













I need to implement a simple functionality on keyboard shortcut but combination with 'shift' key not work :( .



 window.onkeydown = (event) => {
if (event.ctrlKey && event.shiftKey) {
switch (event.key) {
case '1':
// something
break;
}
}
}






javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 12:11









Filip Laurentiu

114113




114113












  • shift+numpad1 isn't a number, it's an End key...
    – Chayim Friedman
    Nov 19 at 12:13










  • shift+1 is also !
    – 0.sh
    Nov 19 at 12:14










  • how to make this combination work ? ctrl+shif+numpad1
    – Filip Laurentiu
    Nov 19 at 12:16










  • Possible duplicate of How to detect if multiple keys are pressed at once using JavaScript?
    – Ram Segev
    Nov 19 at 12:17










  • Check this
    – Zohir Salak
    Nov 19 at 19:52




















  • shift+numpad1 isn't a number, it's an End key...
    – Chayim Friedman
    Nov 19 at 12:13










  • shift+1 is also !
    – 0.sh
    Nov 19 at 12:14










  • how to make this combination work ? ctrl+shif+numpad1
    – Filip Laurentiu
    Nov 19 at 12:16










  • Possible duplicate of How to detect if multiple keys are pressed at once using JavaScript?
    – Ram Segev
    Nov 19 at 12:17










  • Check this
    – Zohir Salak
    Nov 19 at 19:52


















shift+numpad1 isn't a number, it's an End key...
– Chayim Friedman
Nov 19 at 12:13




shift+numpad1 isn't a number, it's an End key...
– Chayim Friedman
Nov 19 at 12:13












shift+1 is also !
– 0.sh
Nov 19 at 12:14




shift+1 is also !
– 0.sh
Nov 19 at 12:14












how to make this combination work ? ctrl+shif+numpad1
– Filip Laurentiu
Nov 19 at 12:16




how to make this combination work ? ctrl+shif+numpad1
– Filip Laurentiu
Nov 19 at 12:16












Possible duplicate of How to detect if multiple keys are pressed at once using JavaScript?
– Ram Segev
Nov 19 at 12:17




Possible duplicate of How to detect if multiple keys are pressed at once using JavaScript?
– Ram Segev
Nov 19 at 12:17












Check this
– Zohir Salak
Nov 19 at 19:52






Check this
– Zohir Salak
Nov 19 at 19:52














3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










The key code switches to an exclamation point because SHIFT is being held. Changing the case in your switch to '!' from '1' is a possible solution. However you may be using a numpad. I would recommend avoiding the key in this scenario and just getting the event.code.



window.onkeydown = (event) => {
if (event.ctrlKey && event.shiftKey) {
switch (event.code) {
case 'Digit1':
alert()
break;
}
}
}


I hope this helps.






share|improve this answer






























    up vote
    0
    down vote













    When you are pressing Shift, the event.key will be the character that was pressed. In your case when you press Shift + 1 it will be !.



    One possible solution would be to use event.code property.
    For numpad it will give Digit1, Digit2, etc.






    share|improve this answer





















    • No, numpad1, not the normal 1 (the numbers key in the right side of the keyboards. Numbers only if NumLock is turned on).
      – Chayim Friedman
      Nov 19 at 12:21












    • I also try this, KeyCode for numpad1 is 97, but after I press ctrl+shift + (any numpad number ) the 'shift' press event still fire.
      – Filip Laurentiu
      Nov 19 at 12:24


















    up vote
    0
    down vote













     if (event.ctrlKey && event.code === 'Numpad1')


    this works






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374380%2fshortcut-key-not-working-ctrl-shift-numpad1%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote



      accepted










      The key code switches to an exclamation point because SHIFT is being held. Changing the case in your switch to '!' from '1' is a possible solution. However you may be using a numpad. I would recommend avoiding the key in this scenario and just getting the event.code.



      window.onkeydown = (event) => {
      if (event.ctrlKey && event.shiftKey) {
      switch (event.code) {
      case 'Digit1':
      alert()
      break;
      }
      }
      }


      I hope this helps.






      share|improve this answer



























        up vote
        1
        down vote



        accepted










        The key code switches to an exclamation point because SHIFT is being held. Changing the case in your switch to '!' from '1' is a possible solution. However you may be using a numpad. I would recommend avoiding the key in this scenario and just getting the event.code.



        window.onkeydown = (event) => {
        if (event.ctrlKey && event.shiftKey) {
        switch (event.code) {
        case 'Digit1':
        alert()
        break;
        }
        }
        }


        I hope this helps.






        share|improve this answer

























          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          The key code switches to an exclamation point because SHIFT is being held. Changing the case in your switch to '!' from '1' is a possible solution. However you may be using a numpad. I would recommend avoiding the key in this scenario and just getting the event.code.



          window.onkeydown = (event) => {
          if (event.ctrlKey && event.shiftKey) {
          switch (event.code) {
          case 'Digit1':
          alert()
          break;
          }
          }
          }


          I hope this helps.






          share|improve this answer














          The key code switches to an exclamation point because SHIFT is being held. Changing the case in your switch to '!' from '1' is a possible solution. However you may be using a numpad. I would recommend avoiding the key in this scenario and just getting the event.code.



          window.onkeydown = (event) => {
          if (event.ctrlKey && event.shiftKey) {
          switch (event.code) {
          case 'Digit1':
          alert()
          break;
          }
          }
          }


          I hope this helps.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 at 19:46

























          answered Nov 19 at 19:17









          Jesse

          2,30211331




          2,30211331
























              up vote
              0
              down vote













              When you are pressing Shift, the event.key will be the character that was pressed. In your case when you press Shift + 1 it will be !.



              One possible solution would be to use event.code property.
              For numpad it will give Digit1, Digit2, etc.






              share|improve this answer





















              • No, numpad1, not the normal 1 (the numbers key in the right side of the keyboards. Numbers only if NumLock is turned on).
                – Chayim Friedman
                Nov 19 at 12:21












              • I also try this, KeyCode for numpad1 is 97, but after I press ctrl+shift + (any numpad number ) the 'shift' press event still fire.
                – Filip Laurentiu
                Nov 19 at 12:24















              up vote
              0
              down vote













              When you are pressing Shift, the event.key will be the character that was pressed. In your case when you press Shift + 1 it will be !.



              One possible solution would be to use event.code property.
              For numpad it will give Digit1, Digit2, etc.






              share|improve this answer





















              • No, numpad1, not the normal 1 (the numbers key in the right side of the keyboards. Numbers only if NumLock is turned on).
                – Chayim Friedman
                Nov 19 at 12:21












              • I also try this, KeyCode for numpad1 is 97, but after I press ctrl+shift + (any numpad number ) the 'shift' press event still fire.
                – Filip Laurentiu
                Nov 19 at 12:24













              up vote
              0
              down vote










              up vote
              0
              down vote









              When you are pressing Shift, the event.key will be the character that was pressed. In your case when you press Shift + 1 it will be !.



              One possible solution would be to use event.code property.
              For numpad it will give Digit1, Digit2, etc.






              share|improve this answer












              When you are pressing Shift, the event.key will be the character that was pressed. In your case when you press Shift + 1 it will be !.



              One possible solution would be to use event.code property.
              For numpad it will give Digit1, Digit2, etc.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 19 at 12:19









              Daniil Andreyevich Baunov

              1,022526




              1,022526












              • No, numpad1, not the normal 1 (the numbers key in the right side of the keyboards. Numbers only if NumLock is turned on).
                – Chayim Friedman
                Nov 19 at 12:21












              • I also try this, KeyCode for numpad1 is 97, but after I press ctrl+shift + (any numpad number ) the 'shift' press event still fire.
                – Filip Laurentiu
                Nov 19 at 12:24


















              • No, numpad1, not the normal 1 (the numbers key in the right side of the keyboards. Numbers only if NumLock is turned on).
                – Chayim Friedman
                Nov 19 at 12:21












              • I also try this, KeyCode for numpad1 is 97, but after I press ctrl+shift + (any numpad number ) the 'shift' press event still fire.
                – Filip Laurentiu
                Nov 19 at 12:24
















              No, numpad1, not the normal 1 (the numbers key in the right side of the keyboards. Numbers only if NumLock is turned on).
              – Chayim Friedman
              Nov 19 at 12:21






              No, numpad1, not the normal 1 (the numbers key in the right side of the keyboards. Numbers only if NumLock is turned on).
              – Chayim Friedman
              Nov 19 at 12:21














              I also try this, KeyCode for numpad1 is 97, but after I press ctrl+shift + (any numpad number ) the 'shift' press event still fire.
              – Filip Laurentiu
              Nov 19 at 12:24




              I also try this, KeyCode for numpad1 is 97, but after I press ctrl+shift + (any numpad number ) the 'shift' press event still fire.
              – Filip Laurentiu
              Nov 19 at 12:24










              up vote
              0
              down vote













               if (event.ctrlKey && event.code === 'Numpad1')


              this works






              share|improve this answer

























                up vote
                0
                down vote













                 if (event.ctrlKey && event.code === 'Numpad1')


                this works






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                   if (event.ctrlKey && event.code === 'Numpad1')


                  this works






                  share|improve this answer












                   if (event.ctrlKey && event.code === 'Numpad1')


                  this works







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 days ago









                  Filip Laurentiu

                  114113




                  114113






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374380%2fshortcut-key-not-working-ctrl-shift-numpad1%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                      Npm cannot find a required file even through it is in the searched directory