I'm trying to use the accessibility API to get the active window, the problem is when I try to get the focused application I get a cannot complete error. Below is a small piece of my code:
AXUIElementRef systemElement =
AXUIElementCreateSystemWide();
AXUIElementRef focused = nullptr;
AXError error = AXUIElementCopyAttributeValue (systemElement,
kAXFocusedApplicationAttribute, (CFTypeRef*) &focused);
// error value results in kAXErrorCannotComplete
I have accessibility enabled and have compared my code to code I found on GitHub but nothing seems to work and I'm fresh out of ideas. Perhaps I'm overlooking something?