为什么我无法访问 NSEvent?
我正在尝试使用 NSEvent,但是如果我尝试访问该类,则会出现错误。我起初以为这是因为我试图从 main 方法中使用它,但即使当我尝试在类中使用它时,它仍然无法构建。
这是我的代码:
#import <Foundation/Foundation.h>
#import <appkit/NSEvent.h>
@interface Test : NSObject
@end
@implementation Test
-(id) init {
self = [super init];
if (self) {
NSLog(@"New Test Class");
NSLog(@"%@", [NSEvent class]);
}
return self;
}
@end
int main (int argc, const char * argv[])
{
@autoreleasepool {
NSUInteger eventMask = NSKeyDownMask;
Test *t = [[Test alloc] init];
/*id eventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:eventMask handler:^(NSEvent *incomingEvent)
{
NSEvent *result = incomingEvent;
NSLog(@"%i", (int)[result keyCode]);
return result;
}];*/
}
return 0;
}
这是我收到的错误:
I am trying to use NSEvent, however if I try to access the class I get an error. I at first thought that it was because I was trying to use it from the main method, but even when I tried to use it in a class it still won't build.
Here is my code:
#import <Foundation/Foundation.h>
#import <appkit/NSEvent.h>
@interface Test : NSObject
@end
@implementation Test
-(id) init {
self = [super init];
if (self) {
NSLog(@"New Test Class");
NSLog(@"%@", [NSEvent class]);
}
return self;
}
@end
int main (int argc, const char * argv[])
{
@autoreleasepool {
NSUInteger eventMask = NSKeyDownMask;
Test *t = [[Test alloc] init];
/*id eventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:eventMask handler:^(NSEvent *incomingEvent)
{
NSEvent *result = incomingEvent;
NSLog(@"%i", (int)[result keyCode]);
return result;
}];*/
}
return 0;
}
This is the error that I am getting:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否链接到 AppKit 框架?您的
#import
语句会让我相信这一步可能被遗漏了。您可以通过将 AppKit 添加到 Xcode 中的项目来修复此问题,或者如果使用命令行,则添加-framework AppKit
。Are you linking against the AppKit framework? Your
#import
statements would lead me to believe that step might have been missed. You can fix it by adding AppKit to your project in Xcode, or if you use the command line, add-framework AppKit
.