在 64 位应用程序中使用的等效 Carbon 32 位调用 - GetApplicationEventTarget()
我正在编写一个 64 位 Cocoa 应用程序。我需要注册参加全球重大活动。所以我写了这段代码:
- (void)awakeFromNib
{
EventHotKeyRef gMyHotKeyRef;
EventHotKeyID gMyHotKeyID;
EventTypeSpec eventType;
eventType.eventClass=kEventClassKeyboard;
eventType.eventKind=kEventHotKeyPressed;
eventType.eventClass=kEventClassKeyboard;
eventType.eventKind=kEventHotKeyPressed;
InstallApplicationEventHandler(&MyHotKeyHandler,1,&eventType,NULL,NULL);
gMyHotKeyID.signature='htk1';
gMyHotKeyID.id=1;
RegisterEventHotKey(49, cmdKey+optionKey, gMyHotKeyID,
**GetApplicationEventTarget**(), 0, &gMyHotKeyRef);
}
但是由于 64 位应用程序不支持 GetApplicationEventTarget()
我收到错误。如果我声明它,那么我不会收到任何错误,但应用程序会崩溃。
是否有任何等效的方法可以在 64 位应用程序中使用 GetApplicationEventTarget()
(在 Carbon 框架中定义)。
或者有什么方法可以使用可可调用来获取全局关键事件?
任何帮助表示赞赏。
谢谢, 迪拉杰。
I'm writing a 64-bit Cocoa application. I need to register for global key events. So I wrote this piece of code :
- (void)awakeFromNib
{
EventHotKeyRef gMyHotKeyRef;
EventHotKeyID gMyHotKeyID;
EventTypeSpec eventType;
eventType.eventClass=kEventClassKeyboard;
eventType.eventKind=kEventHotKeyPressed;
eventType.eventClass=kEventClassKeyboard;
eventType.eventKind=kEventHotKeyPressed;
InstallApplicationEventHandler(&MyHotKeyHandler,1,&eventType,NULL,NULL);
gMyHotKeyID.signature='htk1';
gMyHotKeyID.id=1;
RegisterEventHotKey(49, cmdKey+optionKey, gMyHotKeyID,
**GetApplicationEventTarget**(), 0, &gMyHotKeyRef);
}
But since GetApplicationEventTarget()
is not supported for 64-bit applications I'm getting errors. If I declare it, then I don't get any errors but the application crashes.
Is there any equivalent method for GetApplicationEventTarget()
(defined in Carbon framework) to use in 64-bit applications.
Or is there any way to get the global key events using cocoa calls?
Any help is appreciated.
Thanks,
Dheeraj.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我为 Carbon 热键编写了一个 Cocoa 包装器(据我的测试显示,它可以在 64 位应用程序中运行),您可以在 github 上找到它:http://github.com/davedelong/DDHotKey
我正在使用
GetEventDispatcherTarget()
进行热键注册。I wrote a Cocoa wrapper for Carbon hot keys (and as far as my testing showed, it works in 64-bit apps), and you can find it on github here: http://github.com/davedelong/DDHotKey
I'm using
GetEventDispatcherTarget()
for hotkey registration.当它说 64 位不支持 GetApplicationEventTarget 时,我认为这是一个文档错误。如果您查看 CarbonEvents.h(来自 10.6 SDK),您会发现 GetUserFocusEventTarget 的声明被
#if !__LP64__ ... #endif
括起来,但就在其上方,是 GetApplicationEventTarget 的声明不是。 GetApplicationEventTarget 可能不是崩溃的原因。在您的代码中, gMyHotKeyRef 和 gMyHotKeyID 看起来像是全局变量,但它们是本地变量。I think it is a documentation error when it says that GetApplicationEventTarget is not supported in 64 bits. If you look in CarbonEvents.h (from the 10.6 SDK), you see that the declaration of GetUserFocusEventTarget is bracketed by
#if !__LP64__ ... #endif
, but just above it, the declaration of GetApplicationEventTarget is not. GetApplicationEventTarget is probably not the cause of the crash. In your code, gMyHotKeyRef and gMyHotKeyID look like they were intended to be global variables, but they're local.64 位应用程序不支持 Carbon。有关信息,请参阅此问题的答案关于如何使用 CGEventTap 在 Cocoa 中以受支持的方式执行此操作。
Carbon isn't supported in 64-bit applications. See the answer to this question for information on how to use
CGEventTap
to do this in a supported way in Cocoa.