System-wide recognition of scroll events on Mac OSX and setting focus to a different window
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 开发者_StackOverflow中文版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:
- How can I get a window or window id at a certain location on the screen?
- If I can only get a window id, how can I find the appropriate application or window object to manipulate?
- 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.
精彩评论