How to generate keystroke with repeat in macOS application with objective-c?
I already manage to generate the keystroke:
CGEventRef keyup, keydown;
uint64_t keyModifier=0;
VK = kVK_RightArrow;
keyModifier = 0;
keydown = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)VK, true);
CGEventSetFlags( keydown, keyModifier);
keyup = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)VK, false);
CGEventSetFlags( keyup, keyModifier);
// press the key
// forward them to the frontmost app
CGEventPostToPid (pid, keydown);
// and finally behave friendly
CFRelease(keydown);
....
// somewhere else with time delay
// release the key
// forward them to the frontmost app
CGEventPostToPid (pid, keyup);
// and finally behave friendly
CFRelease(keyup);
Using this code the equivalent keyboard right key is pressed then released, but no repeat although there is enough time between the 2 events.