I am working on a C++ remote control application that posts key injection events to macs as a user on another computer is typing. Previously, the application was using deprecated code to do the key injections:
CGError error = CGPostKeyboardEvent(0, nativeKeyCode, isPressed);
But this had issues with modifier keys like Caps Lock, and we wanted to update the code so it was no longer calling deprecated functions.
After doing some research, I got the Caps Lock modifier key working using the non-deprecated CGEventCreateKeyboardEvent function:
CGEventRef event = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)nativeKeyCode, isPressed);
CGEventPost(kCGHIDEventTap, event);
CFRelease(event);
However, when a user on the remote control application logs out of the mac and is navigated to the mac login screen, this function isn't working when entering a password on that screen. I am able to have logs printed out around every statement, and I've placed everything within a try-catch, but there are no exceptions or other apparent errors occurring. I've reproduced this issue on macOS High Sierra, but it has also been reproduced on macOS Sierra.
From what I've seen of Apple's documentation, there isn't a way to do error checking on these particular functions other than checking if the created event is null. When testing this scenario, event was being created successfully and was not null.
I've been looking for any information related to this but haven't found anyone with this specific issue on the mac login screen. It should be noted that the deprecated code worked just fine on the login screen, and the current code works fine on the lock screen and anywhere else on mac; it's only failing on the login screen when the user has completely logged out.
Has anyone else seen this issue and know of any solutions to it? Or is there anything else obviously wrong with the key injection code?