I need to simulate keystrokes in OSX. Here\'s how I do it:
-(void)execute {
CGEventSourceRef sourceRef =
CGEventSourceCreate(kCGEventSourceStateHIDSy
For the record, while @abarnert's answer is great and that's the way you should do it according to documentation, my original code also works. I found out that I had a different problem not relevant to this question.
So, if you need to apply modifier keys to the keypress, you can simply add them like this CGEventSetFlags(keyPress, modifierFlags);
without pressing an depressing every modifier key separately. That approach works, and I haven't found any drawbacks yet and readability of the code is way better.