I am writing an application that uses the Accessibility API to automate testing of an app. To that effort it needs to click on elements in an application that was written with specific accessibility in mind (yes, I know. A new version is being worked on but this old one is in maintenance mode). To do that a search is executed and a result is displayed on the screen at which point a mouse double click is being simulated on the result.
The problem is that on the machines I’d like to use for testing, a 2010 and a 2012 Mac Pro, after a short while the mouse cursor disappears. When the mouse cursor is not visible, the double-click is ignored and it is not until the part of automation when an AXPress is selected on the menu bar that the cursor returns, for a short while. If I jostle the mouse even a tiny bit the cursor will reappear and things will work as expected, until it disappears again.
My double click code looks like this. Note this code is for a UI element that can be selected and then double clicked. Ideally I’l be eliminating the 1st click:
CGPoint point;
AXValueGetValue(elementValueRef, kAXValueCGPointType, &point);
// Just to be safe move to location
CGEventRef move1 = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, CGPointMake(point.x+15, point.y+15), kCGMouseButtonLeft );
CGEventPost(kCGHIDEventTap, move1);
[NSThread sleepForTimeInterval:0.1f];
move1 = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, CGPointMake(point.x+5, point.y+5), kCGMouseButtonLeft );
CGEventPost(kCGHIDEventTap, move1);
CFRelease(move1);
// In some situations it appears it is safer to select the item before double-clicking it.... This solves that
CGEventRef clickEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, CGPointMake(point.x+5, point.y+5), kCGMouseButtonLeft);
CGEventSetIntegerValueField(clickEvent, kCGMouseEventClickState, 1);
CGEventPost(kCGHIDEventTap, clickEvent);
CGEventSetType(clickEvent, kCGEventLeftMouseUp);
CGEventPost(kCGHIDEventTap, clickEvent);
clickEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, CGPointMake(point.x+5, point.y+5), kCGMouseButtonLeft);
CGEventSetIntegerValueField(clickEvent, kCGMouseEventClickState, 2);
CGEventPost(kCGHIDEventTap, clickEvent);
CGEventSetType(clickEvent, kCGEventLeftMouseUp);
CGEventPost(kCGHIDEventTap, clickEvent);
CGEventSetType(clickEvent, kCGEventLeftMouseDown);
CGEventPost(kCGHIDEventTap, clickEvent);
CGEventSetType(clickEvent, kCGEventLeftMouseUp);
CGEventPost(kCGHIDEventTap, clickEvent);
CFRelease(clickEvent);
These two machines are running 10.11.2. Note this does NOT happen with a 2015 MBPro. There the cursor does not disappear.
Note I have done everything I can to move the cursor in code. I have tried to use the [NSCursor unhide], I have tried setting the cursor to reappear after motion, nothing.