Global NSEvent monitoring for modifier flags returns mixed results

In connection with the global monitoring of changes in the modifier flag, a peculiar problem arises.

Let's assume the monitor is as shown below.

_flagsChangedGlobalEventHandler = [NSEvent addGlobalMonitorForEventsMatchingMask:NSFlagsChangedMask
handler:^(NSEvent *event) {

    NSLog(@"Global flags changed event");

    NSLog(@"[NSEvent modifierFlags] is %i and [event modifierFlags] is %i",
          [NSEvent modifierFlags], [event modifierFlags]);
}

      

Initially, the journal executes the following commands when the left key is pressed:

[NSEvent modifierFlags] is 1048576 and [event modifierFlags] is 1048840

and after releasing the left command:

[NSEvent modifierFlags] is 0 and [event modifierFlags] is 256

Now, after I have moved the window on my MacBook using three fingers in the title bar, the following results from one monitor:

[NSEvent modifierFlags] is 1048576 and [event modifierFlags] is 1048584

and after releasing the left command: [NSEvent modifierFlags] is 0 and [event modifierFlags] is 0

Questions:

  • Why does this [event modifierFlags] return different values, in particular 256 if the modifier is not supported?

  • Why is it that the gesture of moving a finger of three fingers causes [event modifierFlags] to change to -256?

I understand it might have something to do with closing the lid, although I'm not sure why the class and ivar modifierFlags return different results.

I'm on 10.7.3.

+3


source to share





All Articles