• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Posting Keyboard Events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Posting Keyboard Events


  • Subject: Posting Keyboard Events
  • From: Dave DeLong <email@hidden>
  • Date: Fri, 05 Sep 2008 20:15:59 -0600

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Posting Keyboard Events
      • From: Peter N Lewis <email@hidden>
    • Re: Posting Keyboard Events
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: Core Data Form
  • Next by Date: Re: Binding to an NSSet
  • Previous by thread: Re: Binding to an NSSet
  • Next by thread: Re: Posting Keyboard Events
  • Index(es):
    • Date
    • Thread