views:

36

answers:

1

Hi, Im writing a server to receive key events from an iPhone. I can send a message from the iPhone and have my server display it, on the Mac, now i just need to translate that into a Key press, and simulate that press in Cocoa.

Could anyone offer me a starting point, as i guess this is quite low level.

Thanks

A: 

I believe IOHIDPostEvent may be what you're looking for. Something like this:

static void HIDPostVirtualKey(
    const UInt8     inVirtualKeyCode,
    const Boolean   inPostUp,
    const Boolean   inRepeat)
{
    NXEventData     event;
    IOGPoint        loc = { 0, 0 };

    bzero(&event, sizeof(NXEventData));

    event.key.repeat = inRepeat;
    event.key.keyCode = inVirtualKeyCode;
    event.key.origCharSet = event.key.charSet = NX_ASCIISET;
    event.key.origCharCode = event.key.charCode = 0;
    IOHIDPostEvent( get_event_driver(), inPostUp ? NX_KEYUP : NX_KEYDOWN, loc, &event, kNXEventDataVersion, kIOHIDPostHIDManagerEvent, FALSE );
}
somegeekintn