开发者

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);
    CGEve开发者_Python百科ntPost(kCGAnnotatedSessionEventTap, mDown);}
    CFRelease(shiftDown);
    CFRelease(mDown);

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

Any help would be appreciated.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜