1

In Cocoa, i'm working on an app that can send keyboard events. Using CGEventCreateKeyboardEvent seems to be the proper way to do this. I found the following code snippet:

CGEventRef push = CGEventCreateKeyboardEvent(NULL, 123, true);
CGEventRef release = CGEventCreateKeyboardEvent(NULL, 123, false);
CGEventPost(kCGHIDEventTap, push);
CGEventPost(kCGHIDEventTap, release);

Which does a 'left arrow' push, then release, only its using the hardcoded value 123. Although I have been looking around, I haven't been able to find any type of lookup for the possible values. Would anyone be able to point me in the right direction?

Kyle
  • 17,317
  • 32
  • 140
  • 246
  • Looks like an exact dup of http://stackoverflow.com/questions/3202629/where-can-i-find-a-list-of-mac-virtual-key-codes – abarnert Jun 27 '12 at 23:23
  • 1
    PS, another option is to create the events in Cocoa with the NSEvent class, then call its CGEvent method to get the CGEventRef. – abarnert Jun 27 '12 at 23:24
  • @Zenox, do you want to create keyboard events for modifier keys, control keys, or "normal" characters? The latter is hardest, because the key codes vary depending on the keyboard layout. – JWWalker Jun 28 '12 at 00:52

0 Answers0