1

Using addGlobalMonitorForEventsMatchingMask, I can check for keys being pressed. And when an event is fired, I can check the modifier flags to see if any modifiers were used in conjunction.

But I need to know if a modifier is pressed without another key being pressed.

How would I do this?

4

1 回答 1

0

您正在寻找以下类型的事件kCGEventFlagsChanged

CGEventMask eventMask = (1 << kCGEventFlagsChanged);
CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, eventMask, cgEventCallback, NULL);

...


CGEventRef cgEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef cgEvent, void *refcon)
{
    NSEvent *event = [NSEvent eventWithCGEvent:cgEvent];
    if (event.type == kCGEventFlagsChanged) {
        NSLog(@"modifier key!");
    }
}
于 2013-11-08T02:12:33.693 回答