Understanding the difference between CGPostKeyboardEvent and CGEventCreateKeyboardEvent

I need to send a keystroke to the target application, and my first requests led me to CGEventCreateKeyboardEvent :

CGEventRef eventA = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)0, true);
CFRelease(eventA);

This compiled, but did nothing, but in the process of trying to find out, I found this ...

CGPostKeyboardEvent( (CGCharCode)'a', (CGKeyCode)0, true);

... and it worked. What for? From what I have read so far about this, they should do the same thing, but CGPostKeyboardEvent is deprecated.

(Forgive me if I ignore the details that I should explicitly include - I am stepping out of my usual depth trying to help colleagues with an after-school project and just trying to find out something along the way.)

+3
source share
1 answer

, . , , :

CGEventRef a = CGEventCreateKeyboardEvent(NULL, 123, true);
CGEventRef b = CGEventCreateKeyboardEvent(NULL, 123, false);
CGEventPost(kCGHIDEventTap, a);
CGEventPost(kCGHIDEventTap, b);
+3

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


All Articles