How to programmatically emulate Appple special keys such as media navigation & power keys

Media keys along with some other keys are not handled through the standard apple keyboard event subsystem. They are treated differently, and therefore emulating them from software requires special code (EventTap won't work!). Here's a function that does this: void HIDPostAuxKey(uint32_t key, bool down) { @autoreleasepool { NSEvent* ev = [NSEvent otherEventWithType …