5

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 ); 
1
  • You can use SendInput to send unicode characters, but you are limited to UTF-8 since you are limited to a short for wScan. You need to set wVK to 0x00 and set the use unicode flag(0x0004) in dwFlags. Commented Jan 8, 2013 at 18:48

1 Answer 1

5
CGEventRef e = CGEventCreateKeyboardEvent(NULL, NULL, true); CGEventKeyboardSetUnicodeString(e, unicodeStringLength, unicodeString); CGEventPost(kCGHIDEventTap, e); 
Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't look right to pass NULL as the second parameter of CGEventCreateKeyboardEvent, because it's not a pointer. It happens to work, because the NULL is treated as zero, which is a valid key code. Also note that you should say CFRelease(e) at the end.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.