hishamk
hishamk

Reputation: 63

Carbon - OS X - Sending modified key events using CGEventPost

I'm trying to programmatically send modified keystrokes, for instance a capital "A". The problem is that the shift modifier does not seem to have any effect.

In my code, I have two events, one for the shift key down, and another for the 'm' key down.

CGEventRef mDown = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)46, true);

CGEventRef shiftDown = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)56, true);

    CGEventPost(kCGAnnotatedSessionEventTap, shiftDown);
    CGEventPost(kCGAnnotatedSessionEventTap, mDown);}
    CFRelease(shiftDown);
    CFRelease(mDown);

The result is unfortunately always a small case 'm'!

Any help would be appreciated.

Upvotes: 0

Views: 830

Answers (1)

Nicholas Riley
Nicholas Riley

Reputation: 44321

You should be using CGEventKeyboardSetUnicodeString instead. See here for some sample code.

Upvotes: 2

Related Questions