1

I'm registering for global mouse wheel events in my cocoa application. My goal is to have some kind of background application to be able to focus a window of another application when the user scrolls in it's window. If possible with Objective-C and Cocoa, what route would I need to go if I wanted to do this?

My code for the event registering looks like this:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [NSEvent addGlobalMonitorForEventsMatchingMask:
    NSScrollWheelMask handler:^(NSEvent * ev) {
        NSLog(@"%@", ev.description);
    }];
}

This works, but the data captured in the event (like the window or the windowid) I don't seem to be able to manipulate - and the window id doesn't even seem to be the correct one, as I can get a list of windows and get a different id in there - just the screen position seems to be accurate. So three questions to solve this riddle:

  1. How can I get a window or window id at a certain location on the screen?
  2. If I can only get a window id, how can I find the appropriate application or window object to manipulate?
  3. I guess I would need the accessibility API for manipulating the window and giving it focus. How does that work?

Maybe these are simple tasks, but I've not ever written a Mac-Cocoa application before. Before suggesting documentations to read, you should know that I already scanned all the documentation, and that I better learn by example than by reading books :-)

EDIT: I just found out that I might use the ProcessManager to bring the application to the front. If you think this is a possible solution, ho can I get the process id for the window on a certain point on the screen?

EDIT2: I don't want to use Carbon APIs.

Akku
  • 4,373
  • 4
  • 48
  • 67

0 Answers0