Я использую DDHotKey для отслеживания некоторых общесистемных сочетаний клавиш. Когда событие запускается, оно доставляется только моему приложению. Можно ли наблюдать за ним, не препятствуя доставке события в исходное целевое приложение?
Вот как этот модуль регистрирует обработчик событий:
InstallApplicationEventHandler(&dd_hotKeyHandler, 1, &eventSpec, NULL, NULL);
И сам обработчик события:
OSStatus dd_hotKeyHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData) {
@autoreleasepool {
EventHotKeyID hotKeyID;
GetEventParameter(theEvent, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(hotKeyID),NULL,&hotKeyID);
UInt32 keyID = hotKeyID.id;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"hotKeyID = %u", keyID];
NSSet *matchingHotKeys = [[DDHotKeyCenter sharedHotKeyCenter] hotKeysMatchingPredicate:predicate];
if ([matchingHotKeys count] > 1) { NSLog(@"ERROR!"); }
DDHotKey *matchingHotKey = [matchingHotKeys anyObject];
NSEvent *event = [NSEvent eventWithEventRef:theEvent];
NSEvent *keyEvent = [NSEvent keyEventWithType:NSKeyUp
location:[event locationInWindow]
modifierFlags:[event modifierFlags]
timestamp:[event timestamp]
windowNumber:-1
context:nil
characters:@""
charactersIgnoringModifiers:@""
isARepeat:NO
keyCode:[matchingHotKey keyCode]];
[matchingHotKey invokeWithEvent:keyEvent];
}
return noErr;
}