views:

35

answers:

2

My code works perfect if I want to perform an action when pressin 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?

A: 

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

Also look over in this stackoverflow question.

ShiVik
Not that helpful: `keyLocation` does not appear to be correctly supported in any current browser.
Tim Down
+1  A: 

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