0
$(document).keydown(function(event){
switch (event.keyCode){
case 13:
    btnplay();
    $("#short").text("enter");
    break;
case 39:
    btnext();
    $("#short").text("left");
    break;
};
});

This works, but instead case 13 and case 39 now I need case Ctrl+13 and case Ctrl+39.

How to do this.

qadenza
  • 9,025
  • 18
  • 73
  • 126
  • 1
    ctrl is a separate key; you need to detect the ctrl using the same function and set an internal boolean to true, then check for this boolean within your case 13 and case 39 – softwarenewbie7331 Mar 11 '16 at 07:32
  • this question might help with detecting when more than one key is pressed. http://stackoverflow.com/questions/4954403/can-jquery-keypress-detect-more-than-one-key-at-the-same-time – Valeklosse Mar 11 '16 at 07:33
  • 1
    in `event` is a property called `ctrlKey` which provides a boolean that tells you the Ctrl button was pressed or not. – Werner Mar 11 '16 at 07:34
  • @softwarenewbie7331, does it mean `case` inside `case` ? – qadenza Mar 11 '16 at 07:34

1 Answers1

1

You can use event.ctrlKey, example:

$(document).on('keydown', 
 function(event){
  if (event.ctrlKey) { 
 //         ^ here
    switch (event.keyCode) {
      case 13:
        $("#short").text("CTRL + enter");
        break;
      case 37:
        $("#short").text("CTRL + left");
        break;
     }
    }
  }
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre id="short">press CTRL + [enter or left]</pre>

(For the record: left arrow is keycode 37)

See also ...

KooiInc
  • 119,216
  • 31
  • 141
  • 177