0

My code works perfect if I want to perform an action when pressing the ctrl key...

$(document).keydown(function(e){
    if(e.ctrlKey){
        if($('.selected').parent().next().length == 0){
            switchTabs($('.selected').parent().parent().find('a:first'));
            return false;
         }else{
            switchTabs($('.selected').parent().next().children('a'));
            return false;
        }
    }
});

However I only want this code to activate when I press only the right control button...

if(e.rightctrlkey) 

doesn't work... if there is a correct method, what is it?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
David
  • 13,619
  • 15
  • 45
  • 51

2 Answers2

1

You won't be able to do this in general. You can do it in IE only:

// Assuming you have a key event stored in variable 'e':
if (e.ctrlLeft) {
    alert("Left!");
} else if (e.ctrlRight) {
    alert("Right!");
}
Tim Down
  • 318,141
  • 75
  • 454
  • 536
0

Make use of event.keyLocation attribute, Left=0, Right=1. Look over here for details.

Also look over in this stackoverflow question.

Community
  • 1
  • 1
vikmalhotra
  • 9,981
  • 20
  • 97
  • 137