tags:

views:

40

answers:

1

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.

A: 

Did you try setting the event's flags to 0?

Peter Hosey
Nope haven't tried that, figured it would not help because the modifier keys are set by a previous event.Worth a try though.Edit:Worked, thanks!
klaaspieter