I have an NSEvent Keyboard hook callback. I'm looking at the event's modifier flags to tell if the letter should be capitalized.
When Caps-Lock is turned on and shift is held down, and you press a key... that key comes out as a capital letter but both 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 is ON (the light is on)
-Shift is being held down
-Tap [e] key
-Output is "E"
-But output of the above code is FALSE FALSE.
Using either shift OR caps correctly reports the values. Why isn't having both of them on reporting correctly? And if both of them are off... why is the letter still being capitalized?
If this is for some reason correct... how can I tell a normal keypress apart from a keypress with shift and caps held down? (they have the same FALSE-FALSE flags)
You don't want to use ==, you need to use bitwise operators:
if( flags & NSShiftKeyMask ){
...
if( flags & NSAlphaShiftKeyMask ){
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With