Created
August 15, 2011 05:09
-
-
Save draftcode/1145740 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <IOKit/IOCFPlugIn.h> | |
| #include <IOKit/hid/IOHIDKeys.h> | |
| #include <CoreFoundation/CoreFoundation.h> | |
| int main(void) | |
| { | |
| IOReturn result = kIOReturnSuccess; | |
| io_iterator_t hidObjectIterator = 0; | |
| io_object_t hidDevice = IO_OBJECT_NULL; | |
| CFMutableDictionaryRef hidMatchDictionary = 0; | |
| CFMutableDictionaryRef hidProperties = 0; | |
| hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey); | |
| result = IOServiceGetMatchingServices(kIOMasterPortDefault, | |
| hidMatchDictionary, | |
| &hidObjectIterator); | |
| if ((result != kIOReturnSuccess) || (hidObjectIterator == 0)) { | |
| printf("Can't obtain an IO iterator\n"); | |
| exit(1); | |
| } | |
| while ((hidDevice = IOIteratorNext(hidObjectIterator))) { | |
| hidProperties = 0; | |
| int vendor = 0, product = 0; | |
| result = IORegistryEntryCreateCFProperties(hidDevice, &hidProperties, | |
| kCFAllocatorDefault, kNilOptions); | |
| if ((result == KERN_SUCCESS) && hidProperties) { | |
| CFNumberRef vendorRef, productRef; | |
| vendorRef = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDVendorIDKey)); | |
| productRef = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductIDKey)); | |
| if (vendorRef) { | |
| CFNumberGetValue(vendorRef, kCFNumberIntType, &vendor); | |
| CFRelease(vendorRef); | |
| } | |
| if (productRef) { | |
| CFNumberGetValue(productRef, kCFNumberIntType, &product); | |
| CFRelease(productRef); | |
| } | |
| } | |
| printf("Got a device: vendor %04x, product %04x\n", vendor, product); | |
| IOObjectRelease(hidDevice); | |
| } | |
| IOObjectRelease(hidObjectIterator); | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment