Getting the modifier key pressed in the CGEvent channel

Having set the response to the event, I cannot determine which key was pressed using CGEvent.

 CGEventFlags flagsP;

 flagsP=CGEventGetFlags(event);

 NSLog(@"flags: 0x%llX",flagsP);
 NSLog(@"stored: 0x%llX",kCGEventFlagMaskCommand);

 if (flagsP==kCGEventFlagMaskCommand) {
       NSLog(@"command pressed");
    }

Given the snippet above, the first NSLog returns a different value from the second NSLog. Not surprisingly, a conditional value never fires when a command modifier key is pressed.

I need to determine if a command, alternative, optional, control or shift, is pressed for a given CGEvent. At first, although I need help to understand why the above does not work.

Thank!

+3
source share
1 answer

-, -ORed , CGEventGetFlags ( ).

, -. .

, bitwise-AND (&). , :

BOOL commandKeyIsPressed = (flagsP & kCGEventFlagMaskCommand) == kCGEventFlagMaskCommand;

?

& , , CGEventFlags, BOOL, signed char. == 1 0, BOOL.

(!!) BOOL _Bool, Boolean BOOL. C99 _Bool ( BOOL stdbool.h) 1, 0, == !!.

+6

Source: https://habr.com/ru/post/1779822/


All Articles