views:

171

answers:

1

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.

+2  A: 

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

Nicholas Riley