Mac Cocoa How to scroll another App that under a v

2019-08-17 08:08发布

问题:

I'm trying to make a screenshot capture App. The App will first place a semitransparent full screen dark view over other Apps, this will make other Apps not responding to mouse scrolling event. How can I set a view covers other Apps and keep them respond to scrolling event? Thanks.

  1. Ignore MyApp's dark view?

or

  1. Send event to other Apps in MyApp?
 -(void)scrollWheel:(NSEvent *)theEvent {
    NSLog(@"user scrolled %f horizontally and %f vertically", [theEvent deltaX], [theEvent deltaY]);
}

Edited:

Found a way to get a App's pid and Followed @Willeke's reference, write the following code, but not work.

-(void)scrollWheel:(NSEvent *)theEvent {
    [super scrollWheel:theEvent];

    CGEventRef wheelevent = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, 1, theEvent.deltaY, theEvent.deltaX);

    // AppPid is gotten before mouse wheel scrolls
    CGEventPostToPid(AppPid, wheelevent);

    CFRelease(wheelevent);
}