Hi everyone,

I'm having a heck of a time figuring out how to post keyboard events. I've been working on this for a couple hours, googling everything I can think of, but I'm still stuck.

First off, I'm aware of the functions:
CGPostKeyboardEvent()
CGEventCreateKeyboardEvent()
CGEventPost()

I've tried every combination of those that I can think of. For modifier keys, it "seems" to work, but when it comes to actual letter keys, it craps out on me. For example, if I try to do:
        CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)56, true);
        CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)6, true);
        CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)6, false);
        CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)56, false);

I'm expecting a capital "A" to get typed. All I get is a system beep once I try to type the A. (Line 2)

So I tried a different way:

CGEventRef shiftDown = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)56, true); CGEventRef shiftUp = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)56, false); CGEventRef aDown = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)6, true);
        CGEventRef aUp = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)6, false);
        
        CGEventPost(kCGHIDEventTap, shiftDown);
        CGEventPost(kCGHIDEventTap, aDown);
        CGEventPost(kCGHIDEventTap, aUp);
        CGEventPost(kCGHIDEventTap, shiftUp);

Again the beep.

Then I found a reference to needing this beforehand: CFRelease(CGEventCreate(NULL));

Guess what!  I still get the beep.

SKIMMERS START READING HERE:

How on earth can I post system keyboard events (without getting a beep)?

Thanks a bunch!

Dave DeLong

ps - Mac OS X 10.5.4, Xcode 3.1, Mac Mini Core Duo
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to