1

我的Run Loop Observer是这样写的:

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);
    }
}

每次我在应用程序中按下任何键时,observerCallback都会被调用 4 次。问题是:如何在observerCallback中获取关键代码?谢谢。

4

1 回答 1

0

根据对您问题的评论,您需要一个本地事件监视器,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

于 2014-01-24T04:17:40.780 回答