Search code examples
objective-cmacosnsevent

keyboard events not getting called in mountain lion


I want to receive notification for any keyboard event in my application, the following code in applitionDidFinishLaunching method ,is working well on lion but its not getting called on mountain lion.

 [NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:^(NSEvent *event) {

NSLog(@"key pressed");        
    }];

I am getting mouse moved event but not working for keyboard events.


Solution

  • If you want to receive key down events globally, then you must set following settings in your mac:

    System Preferences ---> Accessibility --> and check the Enable access for assistive devices (atleast for keyboard)

    then your system can receive key down events globally.