Re: Emulating Pro Keyboard Multimedia Keys
Re: Emulating Pro Keyboard Multimedia Keys
- Subject: Re: Emulating Pro Keyboard Multimedia Keys
- From: George Warner <email@hidden>
- Date: Fri, 30 Aug 2002 09:03:35 -0700
On Wed, 28 Aug 2002 22:50:54 -0700, Dave Corder <email@hidden>
wrote:
>
Along the lines of simulating key presses, IOHIDPostEvent() in
>
IOKit/hidsystem/IOHIDLib.h to post events for those keys also looks
>
interesting, but it appears to have to have a device driver to communicate
>
with and I can't seem to find any documentation on it.
Ok, Here's everything you'll need to post the media keys:
[BEGIN]
static io_connect_t get_event_driver(void)
{
static mach_port_t sEventDrvrRef = 0;
mach_port_t masterPort, service, iter;
kern_return_t kr;
if (!sEventDrvrRef)
{
// Get master device port
kr = IOMasterPort( bootstrap_port, &masterPort );
check( KERN_SUCCESS == kr);
kr = IOServiceGetMatchingServices( masterPort, IOServiceMatching(
kIOHIDSystemClass ), &iter );
check( KERN_SUCCESS == kr);
service = IOIteratorNext( iter );
check( service );
kr = IOServiceOpen( service, mach_task_self(),
kIOHIDParamConnectType, &sEventDrvrRef );
check( KERN_SUCCESS == kr );
IOObjectRelease( service );
IOObjectRelease( iter );
}
return sEventDrvrRef;
}
static void HIDPostSysDefinedKey(const UInt8 sysKeyCode )
{
NXEventData event;
kern_return_t kr;
IOGPoint loc = { 0, 0 };
bzero(&event, sizeof(NXEventData));
event.compound.subType = sysKeyCode;
kr = IOHIDPostEvent( get_event_driver(), NX_SYSDEFINED, loc, &event,
kNXEventDataVersion, 0, FALSE );
check( KERN_SUCCESS == kr );
}
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 );
}
[END]
And here's how you use them:
[BEGIN]
HIDPostSysDefinedKey(NX_SUBTYPE_EJECT_KEY);
HIDPostAuxKey(NX_KEYTYPE_MUTE);
HIDPostAuxKey(NX_KEYTYPE_SOUND_UP);
HIDPostAuxKey(NX_KEYTYPE_SOUND_DOWN);
[END]
--
Enjoy,
George Warner,
Mixed Mode Magic Fragment Scientist
Apple Developer Technical Support (DTS)
_______________________________________________
accessibility-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/accessibility-dev
Do not post admin requests to the list. They will be ignored.