Stas Jaro
Stas Jaro

Reputation: 4885

Why can't I access NSEvent?

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: enter image description here

Upvotes: 2

Views: 1595

Answers (1)

Carl Norum
Carl Norum

Reputation: 224844

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.

Upvotes: 2

Related Questions