Short answer:
Use
handleEvent:client:
and listen to theNSFlagsChanged
event.
IMKInputController
implements the IMKServerInput Protocol, which provides three alternatives to handle an event.
- Key binding - using
inputText:client:
anddidCommandBySelector:client:
- Text data only - using
inputText:key:modifiers:client:
- Handle all events - using
handleEvent:client:
Seems like you've only tried the top two. You can achieve the goal with the third option.
Try the following:
override
recognizedEvents:
(from IMKStateSetting Protocol)- (NSUInteger)recognizedEvents:(id)sender { return NSKeyDownMask | NSFlagsChangedMask; }
and use
handleEvent:client:
-(BOOL)handleEvent:(NSEvent*)event client:(id)sender { NSLog(@"handling event: %@", event); return false; }
You can see the printout on every keydown and keyup of the modifiers in Console, including command
and alt
.