问题描述
我正在编写一个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);
}
但由于 GetApplicationEventTarget()$ c $我在遇到64位应用程序不支持c>的错误。如果我声明了它,那么我不会收到任何错误,但是应用程序会崩溃。
GetApplicationEventTarget()是否有任何等效方法
或者是否有任何方法可以使用可可调用获取全局关键事件? / p>
感谢您的帮助。
谢谢
Dheeraj。
当说64位不支持GetApplicationEventTarget时,我认为这是文档错误。如果查看CarbonEvents.h(从10.6 SDK中获取),您会发现GetUserFocusEventTarget的声明由 #if!__ LP64__ ... #endif
括起来,但仅在上方它,不是GetApplicationEventTarget的声明。 GetApplicationEventTarget可能不是崩溃的原因。在您的代码中,gMyHotKeyRef和gMyHotKeyID看起来像是全局变量,但它们是局部变量。
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.
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 32位调用-GetApplicationEventTarget()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!