开发者

How to detect all cursor movements and key presses on a Mac?

开发者 https://www.devze.com 2023-04-07 11:15 出处:网络
What is the best method to detect all cursor movements and key presses on a Mac us开发者_StackOverflow社区ing objective-c on OSX Lion?I did it by installing an event monitor

What is the best method to detect all cursor movements and key presses on a Mac us开发者_StackOverflow社区ing objective-c on OSX Lion?


I did it by installing an event monitor

- (void)monitorEvents
{
    // Monitor all events
    NSUInteger eventMasks =  NSLeftMouseDownMask | NSRightMouseDownMask | NSMouseMovedMask | NSScrollWheelMask | NSKeyDownMask | NSMouseMovedMask | NSEventTypeBeginGesture | NSEventTypeEndGesture;

    eventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:eventMasks handler:^(NSEvent *incomingEvent) 
    {
        NSEvent *result = incomingEvent;

        return result;
    }];
}


Typically, you would subclass NSApplication and override the -sendEvent: method.

0

精彩评论

暂无评论...
验证码 换一张
取 消