Search code examples
macossendinput

How send unicode character to active application?


I need something like SendInput in Windows API.

I see this method, I don't know there is anyway to convert unicode character to virtual Key code.

CGEventRef CGEventCreateKeyboardEvent (
   CGEventSourceRef source,
   CGKeyCode virtualKey,
   bool keyDown
);

Solution

  • CGEventRef e = CGEventCreateKeyboardEvent(NULL, NULL, true);
    CGEventKeyboardSetUnicodeString(e, unicodeStringLength, unicodeString);   
    CGEventPost(kCGHIDEventTap, e);