开发者

Using DDHotKey wrapper for cocoa/carbon instantiate NSWindow

With the help of Dave DeLong and others on stackoverflow I've given my tutorial app a cool hotkey effect but I can't figure out how to make it instantiate the window.

I have the following setup:

A calculator that is not active when first run but has a NSStatusItem icon and menu, with a menu option that opens the main window.

Also, I have added DDHotKeyCenter.h and DDHotKeyCenter to the directory + linked the Carbon.framework.

The NSStatusMenu is connected to the window through:

-(IBAction)activateMain:(id)sender{
  [NSApp activateIgnoringOtherApps:YES];}

What I was wondering is if it's possible to connect the actions fired by the hotkey, using the Blocks method, to the IBAction di开发者_运维问答rectly, or if there's some intermediate step to connect them?

Would it be better to have the DDHotKey fire an NSEvent, or can it even do that?

I seem to be a bit confused about it's implementation.


DDHotKey does not "fire an NSEvent". It invokes a method on an object. You could very easily set up your hotkey to fire the activateMain: method of whatever object owns it:

...
DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
[c registerHotKeyWithKeyCode... target:self action:@selector(activateMain:) object:nil];
...

Or if you wanted to use a block, you could do:

...
DDHotKeyTask task = ^(NSEvent *hkEvent) {
    [NSApp activateIgnoringOtherApps:YES];
};
DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
[c registerHotKeyWithKeyCode... task:task];
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜