I want to create OS X application which shows up and getting focused with system-wide hotkey, and then, with same hotkey it should dissapear and switch focus back. Just like Alfred does it.
The problem is that I can't focus back on application previously used. By focusing back I mean that I can't continue typing in previous app.
Here is my hotkey handler:
OSStatus OnHotKeyEvent(EventHandlerCallRef nextHandler,EventRef theEvent, void *userData)
{
AppDelegate *me = (__bridge AppDelegate*) userData;
EventHotKeyID hkCom;
GetEventParameter(theEvent, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(hkCom), NULL, &hkCom);
if([[me window] isVisible]) {
[[NSApplication sharedApplication] activateIgnoringOtherApps:NO];
[[me window] orderOut:NULL];
}
else {
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
[[me window] makeKeyAndOrderFront:nil];
}
return noErr;
}