All pastes #423283 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-04-04 01:17 UTC
rendered paste body
void InterruptReportCallbackFunction
              (void *	 		target,
               IOReturn 		result,
               void * 			refcon,
               void * 			sender,
               UInt32		 	bufferSize)
{
    HIDDataRef hidDataRef = (HIDDataRef)refcon;
	int index, inputKey;

	kern_return_t   kr;
	io_service_t    serviceObject;
	io_connect_t	dataPort = 0;
	int				keyCode  = 0;
	
    if ( !hidDataRef )
        return;

    printf("Buffer = ");

    for ( index=0; index<bufferSize; index++)
	{
        printf("%2.2x ", hidDataRef->buffer[index]);
		switch(hidDataRef->buffer[index])
		{
			case 0x4f:
				keyCode = 1;
				printf("Right detected");
				break;
			case 0x50:
				keyCode = 2;
				printf("Left detected");
				break;
			case 0x51:
				keyCode = 3;
				printf("Down detected");
				break;
			case 0x52:
				keyCode = 4;
				printf("Up detected");
				break;
		}
	}
    printf("\n");
	
	mach_port_t iokitPort;
	IOMasterPort (MACH_PORT_NULL, &iokitPort);
	io_registry_entry_t options = IORegistryEntryFromPath (iokitPort, "IRKeyboardEmu"); //Probably not right
	
	if (options) {
		CFTypeRef keys[1] = {
			CFSTR ("keyCode");
		};
		
		CFTypeRef values[1] = {
			CFNumberCreate(NULL, kCFNumberShortType, &keyCode);
		};
		
		CFDictionaryRef dict = CFDictionaryCreate (kCFAllocatorDefault, keys, values, 1, 
				&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
		if (dict) {
			IORegistryEntrySetCFProperties (options, dict);
			CFRelease (dict);
		}
		IOObjectRelease (options);
	}
}