I'm using CGEventCreateKeyboardEvent
to create and CGEventPost
to post an event on the Mac. The following code works perfectly for pressing the 'a' key.
CGEventRef downEvent = CGEventCreateKeyboardEvent(NULL, 0, YES);
CGEventPost(kCGHIDEventTap, downEvent);
CFRelease(downEvent);
The problem lies in the fact that the user might have a modifier key pressed. For example when the user already has the Command key pressed while my keyboard events are send, Command + a will be sent to the active application in stead of just the character a.
Is there a way to work around this? Can I explicitly say that I want to post a character, ignoring any (modifier) keys that might have already been pressed.