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

爱⌒轻易说出口 提交于 2019-12-29 07:35:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!