Re: Eject Key Code
Re: Eject Key Code
- Subject: Re: Eject Key Code
- From: Casey Fleser <email@hidden>
- Date: Mon, 26 Jun 2006 12:52:34 -0500
Check this post:
http://www.cocoabuilder.com/archive/message/cocoa/2004/10/5/118853
The relevant bits of which are:
#import <IOKit/hidsystem/IOHIDLib.h>
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 inSysKeyCode )
{
NXEventData event;
kern_return_t kr;
IOGPoint loc = { 0, 0 };
bzero(&event, sizeof(NXEventData));
event.compound.subType = inSysKeyCode;
kr = IOHIDPostEvent( get_event_driver(), NX_SYSDEFINED, loc, &event,
kNXEventDataVersion, 0, FALSE );
check( KERN_SUCCESS == kr );
}
@implementation NSWorkspace(TrayOpening)
- (void) openCDTray {
HIDPostSysDefinedKey(NX_SUBTYPE_EJECT_KEY);
}
@end
Casey
On Jun 26, 2006, at 12:41 PM, Damien Bobillot wrote:
Daniel Tse worte :
I was wondering if someone can tell what the keycode for the Eject
Key is. Similarly, is there any documentation on the keycodes of
all the other non-ASCII keys like Caps Lock, the volume up/down
keys on the standard mac keyboard? I have tried searching Apple/
Developer but didn't find any tables or docs. I even tried using a
key event grabber but the eject key takes precedence and it's not
registered.
The eject key, like sound/light up/down keys, don't have an
associated keycode and can't be accessed/listened with official
APIs (even with GetEventMonitorTarget() and CGEventTapCreate()).
You may need to write a kernel extension, or raw keyboard reading
to access them.
--
Damien Bobillot
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden