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
objective-c cocoa macos nsevent


source to share


No one has answered this question yet

See similar questions:

13
Check the Flags NSEvent modifier if a specific modifier was clicked but no other

or similar:

131
Force iTerm to translate the meta key just like it does on other operating systems
23
Monitoring global NSEvent in the background
ten
How to control the state of the global modifier key (in any application)?
4
cocoa - the screen is not refreshed after pressing the CGEventPost button
4
Limiting mouse to one display on Mac (potentially using Cocoa)
3
How to follow a swipe gesture around the world in OS X
2
NSEvent modifier flags are not updated until mice move
1
Caps key close and close events detection with CGEvent
0
NSEvent timestamp accuracy for input events (keyboard / mouse)?
0
Running NSEvent to Add Modifier Problem



All Articles
Loading...
X
Show
Funny
Dev
Pics