title: CGEventPostToPSN - How to send keys with different keyboard locales?
body: <p>So I'm sending key presses to another application, like so:</p>
  
  <pre><code>- (void)keyPress:(int)hotkey withModifier:(unsigned int)modifier withKeyDown:(BOOL)keyDown{
  
  
  // verify the process still exists
  ProcessSerialNumber psn = [self myPSN];
  CGEventRef keyEvent = NULL;
  
  // create our source
  CGEventSourceRef source = NULL; // this didn't used to be NULL, does this matter?
  if ( source || 1 == 1 ){
  
      keyEvent = CGEventCreateKeyboardEvent(source, (CGKeyCode)hotkey, keyDown);
  
      // set flags for the event (does this even matter? No.)
      CGEventSetFlags( keyEvent, modifier );
  
      // hit any specified modifier keys
      if ( modifier &amp; NSAlternateKeyMask ){
          PostKeyboardEvent( source, kVK_Option, keyDown );
      }
      if ( modifier &amp; NSShiftKeyMask ){
          PostKeyboardEvent( source, kVK_Shift, keyDown );
      }
      if ( modifier &amp; NSControlKeyMask ){
          PostKeyboardEvent( source, kVK_Control, keyDown );
      }
      if ( modifier &amp; NSCommandKeyMask ){
          PostKeyboardEvent( source, kVK_Command, keyDown );
      }
  
      // post the actual event
      CGEventPostToPSN(&amp;psn, keyEvent);
      usleep(30000);
  
      // post it again if we're doing key up, just in case!
      if ( !keyDown ){
          CGEventPostToPSN(&amp;psn, keyEvent);
      }
  
      // release
      if ( keyEvent ){
          CFRelease(keyEvent);
      }
  }
  }
  </code></pre>
  
  <p>Basically, I can send keys FINE if they are using a US Keyboard, such as sending: kVK_ANSI_A</p>
  
  <p>The problem is with non-US keyboards, how can I adapt these keys to still send correctly if the keyboard layout is NOT set to US?</p>
  
  <p>Here are the virtual key codes I'm having trouble with: <a href="http://pastebin.com/qXnXHb5M" rel="nofollow">http://pastebin.com/qXnXHb5M</a></p>
  
  <p>Thanks in advance!</p>