1
votes

I'd like to have a callback that fires whenever {shift | cmd | ctrl | alt | capslock } are pressed down and released; that is, one callback for key down and a different one for key up. The reason I need the callbacks is because I also want the exact time they are pressed down and released. Unfortunately it doesn't seem like there is an easy way of doing this as modifier keys are handled very differently than normal keys. I have

[NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask
                                       handler:^(NSEvent *event){ [self handleKeyDown:event]; }];
[NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyUpMask
                                       handler:^(NSEvent *event){ [self handleKeyUp:event]; }];

set up to handle normal keys right now. How do I do this for modifier keys? Also, I would like this globally, including outside of my app.

1

1 Answers

1
votes

I think what you are looking for is the event NSFlagsChanged and the corresponding NSFlagsChangedMask.