问题
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?
回答1:
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!");
}
}
回答2:
In Swift:
let isLeftShift = event.modifierFlags.rawValue & UInt(NX_DEVICELSHIFTKEYMASK) != 0
let isRightShift = event.modifierFlags.rawValue & UInt(NX_DEVICERSHIFTKEYMASK) != 0
来源:https://stackoverflow.com/questions/10715910/is-there-a-way-to-differentiate-between-left-and-right-shift-keys-being-pressed