Question

My Run Loop Observer is written as follows:

void observerCallback(CFRunLoopObserverRef observer,
    CFRunLoopActivity activity, void* info)
{
    println("%u", activity);
}
//----------------------------- 
void InstallObserver()
{
    CFRunLoopObserverRef myObserver = NULL;
    int myActivities = kCFRunLoopEntry;

    myObserver = CFRunLoopObserverCreate(NULL, myActivities, YES,
        /* repeat */ 0, &observerCallback, NULL);

    if (myObserver)
    {
        CFRunLoopAddObserver(CFRunLoopGetCurrent(), myObserver,
            kCFRunLoopCommonModes);
    }
}

Every time I press any key in my Application the observerCallback is called 4 times. The question is: How can I obtain key code inside observerCallback? Thanks.

Was it helpful?

Solution

Based on the comments on your question, you want a local event monitor, AKA:

+[NSEvent addLocalMonitorForEventsMatchingMask:handler:]

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/Reference/Reference.html#//apple_ref/occ/clm/NSEvent/addLocalMonitorForEventsMatchingMask:handler:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top