Universal MediaKeys
March 15, 2006
Some time ago George Warner created a handy little set of utilities for simulating various key presses and it can still be found on his .mac file sharing page along with all sorts of other goodies. Really worth a look.
However I noticed a little wrinkle in the HIDPostAuxKey function (MediaKeys project) this morning which is listed as:
static void HIDPostAuxKey(const UInt8 auxKeyCode ) { NXEventData event; kern_return_t kr; IOGPoint loc = { 0, 0 }; bzero(&event, sizeof(NXEventData)); event.compound.subType = NX_SUBTYPE_AUX_CONTROL_BUTTONS; event.compound.misc.S[0] = auxKeyCode; event.compound.misc.C[2] = NX_KEYDOWN; kr = IOHIDPostEvent( get_event_driver(), NX_SYSDEFINED, loc, &event, kNXEventDataVersion, 0, FALSE ); check( KERN_SUCCESS == kr ); }
This is great on a big endian machine, but really the misc data wants to be written as a long or it won’t be interpreted correctly on a little endian (Intel) machine. You probably want to do something like this:
static void HIDPostAuxKey(const UInt8 auxKeyCode ) { NXEventData event; kern_return_t kr; IOGPoint loc = { 0, 0 }; UInt32 evtInfo = inAuxKeyCode << 16 | NX_KEYDOWN << 8; bzero(&event, sizeof(NXEventData)); event.compound.subType = NX_SUBTYPE_AUX_CONTROL_BUTTONS; event.compound.misc.L[0] = evtInfo; kr = IOHIDPostEvent( get_event_driver(), NX_SYSDEFINED, loc, &event, kNXEventDataVersion, 0, FALSE ); check( KERN_SUCCESS == kr ); }
Anyway, thought someone might find that useful.
Aha, thanks for this! I was wondering why posting events for media keys wasn’t working on intel macs.
Ditto on the thanks, much appreciated!
Ah, awesome. Much thanks for this!
Thanks for the code snippets – it was just what I was looking for.
Do you happen to know where I can get a copy of George Warner utilities you link to? The link above is stale, and google isn’t any help.
Thanks, G
I’m afraid I don’t. Maybe I can find something on my computer somewhere. I’ll dig around.
Browsing your site I realized that you are probably responsible for Proxi – fantastic app – shame my AirClick is now dead and can’t be replaced. Thanks for making the AirClick incredibly useful.
That was me. Thanks! I wish I could do something more with it.
Do you know why this does not work for the constant NX_KEYTYPE_NEXT?