Carriage Return in Mac Excel 2008
-
I am attempting to simulate keystrokes on OS X using Qt 5.3, Excel 2008 and the CGEventKeyboardSetUnicodeString function.
The problem is that if I send an "\r" to the following function, it is creating a newline WITHIN the active cell in Excel. I want it to advance to the adjacent cell, similar to how you manually advance with the ENTER key based on the value of the "After pressing RETURN, move selection" setting in Preferences/Edit.
Is there a way to get this to work from code exactly the way it is entered in the Excel app manually?
@NSString * text = [NSString stringWithUTF8String: pTextToPrint.toUtf8().data()];
const char *buffer = [text cStringUsingEncoding:NSUTF16StringEncoding]; CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); CGEventRef keyEventDown = CGEventCreateKeyboardEvent(eventSource, 0, true); CGEventKeyboardSetUnicodeString(keyEventDown, [text length], (UniChar *)buffer); CGEventPost(kCGHIDEventTap, keyEventDown); CFRelease(keyEventDown); CFRelease(eventSource);@