objective-cmacoscocoansevent

Is there a way to differentiate between left and right Shift keys being pressed?


I can recognize when the user presses any Shift key with this code:

-(void)flagsChanged:(NSEvent *)theEvent
{
    if ([theEvent modifierFlags] & NSShiftKeyMask)
        //. . .
}

but is there any way to distinguish whether it was the right or left Shift key that was pressed?


Solution

  • You can do it like this:

    -(void)flagsChanged:(NSEvent *)theEvent {
    
        if ([theEvent modifierFlags] == 131330) {
            NSLog(@"Left shift pressed!");
        }
    
        if ([theEvent modifierFlags] == 131332) {
            NSLog(@"Right shift pressed!");
        }
    }