How can I send a keyboard event to the application with the click of a button?

i'm actually creating a virtual keyboard how can i send a keyboard event to a program by clicking a button? thank

+3
source share
1 answer

You can use Quartz Event Servcices .
They provide CGEventCreateKeyboardEventthat allows you to emulate any physical keystroke.
The API is modeled after real-key events.
Therefore, you must call "Shift" + "Character" to receive the letter in upper case. You also need to release the pressed keys.
Apple documentation contains sample code .

Update:
We are talking about Mac OS X, right? Please add some tags to the original question.

+12
source

Source: https://habr.com/ru/post/1726210/


All Articles