How to develop a virtual keyboard app for mac os

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.

Replies

Just curious, what use is a virtual keyboard on a Mac. There are no Macs with touch screens...

The possible some popeple to call it the soft keyboard ,Because my client's computer havn't keyboard.Can only use the mouse when inputs the content to need such soft keyboard.Therefore I need to design a soft keyboard on mine app

Posting keyboard events via

CGEventPost
is perfectly reasonable. You may find situations where you need to go lower in the input event stack but that’s best avoided unless you have a specific need.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"