I receive events from clicks with a global monitor in macOS. The NSEvent give me coordinates but i need to get the UIElement.
Using the accessibility API, i can get the focused element but i need the clicked element which is totaly different. For example, if i click on a textarea, i get a AXTextArea element. If i click on the application taskbar, the focused element remains AXTextArea which make sense. I want the element associated to the mouse event.
I found on the web a method called accessibilityHitTest which is supposed to retrieve the UIElement under a given NSPoint. I always get null so i am not sure this is supposed to work that way.
Maybe there is another function which retrieve the UIElement from a given point in the screen?
Here is what ive tried :
NSEvent *event; // My event received from global monitoring
id clickedObject = [self accessibilityHitTest:event.locationInWindow];
//This give me an error because self is not a NSWindow.
NSEvent *event; // My event received from global monitoring
id clickedObject =
[[NSApp keyWindow] accessibilityHitTest:event.locationInWindow];
//This give me null at every click.
Maybe this is not possible but i just which i could get the UIElement under my mouse click and not the focused UIElement.