NSEvent modifier flags - error while holding Shift and Caps-Lock?

I have an NSEvent keyboard hook callback. I look at the flags of the event modifier to indicate whether capital letters should follow.

When the Caps-Lock is on and the shift is held down and you press the key ... this key is issued as an uppercase letter, but both the SHIFT and CAPS flags return FALSE .

 //For testing which flags are on. //Holding down Shift and Caps for some reason = FALSE FALSE... NSUInteger flags = [NSEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask; if( flags == NSShiftKeyMask ){ NSLog(@"Shift - TRUE"); } else { NSLog(@"Shift - FALSE"); } if( flags == NSAlphaShiftKeyMask ){ NSLog(@"CAPS - TRUE"); } else { NSLog(@"CAPS - FALSE"); } return newUserKeypress; 

So,

-Caps-Lock on (light on)

-Motion is held

-Tap [e] key

-Exit "E"

-But the output of the above code is FALSE FALSE.

Using either shift OR caps correctly reports values. Why both of them do not have the correct reporting? And if both of them are turned off ... why is the letter still capitalized?

If for some reason this is correct ... how can I say a regular keypress, except for pressing the key with the shift and caps key? (they have the same FALSE-FALSE flags)

+4
source share
1 answer

You do not want to use ==, you need to use bitwise operators:

 if( flags & NSShiftKeyMask ){ ... if( flags & NSAlphaShiftKeyMask ){ 
+10
source

All Articles