使用 DDHotKey 包装器进行 cocoa/carbon 实例化 NSWindow
在 Dave DeLong 和 stackoverflow 上其他人的帮助下,我为我的教程应用程序提供了一个很酷的热键效果,但我不知道如何让它实例化窗口。
我有以下设置:
首次运行时不处于活动状态的计算器,但具有 NSStatusItem 图标和菜单,以及可打开主窗口的菜单选项。
另外,我已将 DDHotKeyCenter.h 和 DDHotKeyCenter 添加到目录并链接到 Carbon.framework。
NSStatusMenu 通过以下方式连接到窗口:
-(IBAction)activateMain:(id)sender{
[NSApp activateIgnoringOtherApps:YES];}
我想知道是否可以使用 Blocks 方法将热键触发的操作直接连接到 IBAction,或者是否有一些中间步骤来连接它们?
让 DDHotKey 触发 NSEvent 会更好吗?或者它甚至可以做到这一点吗?
我似乎对其实现有点困惑。
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 directly, 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DDHotKey 不会“触发 NSEvent”。它调用对象上的方法。您可以非常轻松地设置热键来触发拥有它的任何对象的
activateMain:
方法:或者如果您想使用块,您可以这样做:
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:Or if you wanted to use a block, you could do: