Recently my project involved a virtual keyboard design for mac os,Is similar in our computer /system/library/Input Methods/KeyboardViewer.app .I use the following method:
CGEventRef event1, event2;
event1 = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)5, true);
CGEventPost(kCGSessionEventTap, event1);/
CFRelease(event1);
event2 = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)5, false);
CGEventPost(kCGSessionEventTap, event2);
CFRelease(event2);
Simulation keyboard Input ,but I thought that such method is not good, consults the better method,Thanks very much.