I am trying to create a Cocoa wrapper around a Flash application. I've got it loading up in a WebView, and I can control it by sending key events using the CGEvent API, like so:
[myWindow makeFirstResponder:myFlashWidget];
CGEventRef e1 = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)keyCode, true);
CGEventPost(kCGSessionEventTap, e1);
CFRelease(e1);
When I trigger this from a menu item it works great.
Now I'm adding a global keyboard shortcut to trigger the same function. I am catching the shortcut (via InstallApplicationEventHandler, RegisterEventHotKey) and calling the same function, but it has no effect.
I'm not sure how to diagnose the problem. First obvious thought is that the key focus isn't set properly, but I'm not sure what to call to do it. And I want the shortcut to work even when the window is inactive or hidden. I'm really trying to direct an event to a specific NSView. I've been reading up on event taps but those appear to be solving a different problem.
I'm new to Cocoa so quite possible I'm missing somet开发者_如何学编程hing obvious. Anyone else solved this before? Any approaches to figuring out what's going wrong? Thanks!
I figured it out (mostly) over here: How do I send key events to a Flash movie in WebKit?
精彩评论