Created
December 20, 2015 19:00
-
-
Save EthanArbuckle/d19ae06f1b880174c863 to your computer and use it in GitHub Desktop.
Detect if force touch is supported through IOKit
This file contains 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 <IOKit/hid/IOHIDLib.h> | |
#include <IOKit/hid/IOHIDEventSystem.h> | |
int main(int argc, char **argv, char **envp) { | |
CFMutableDictionaryRef dict = IOServiceMatching("AppleMultitouchN1SPI"); | |
CFDictionaryAddValue(dict, CFSTR(kIOHIDManufacturerKey), CFSTR("Apple Inc.")); | |
io_iterator_t iter; | |
mach_port_t port = kIOMasterPortDefault; | |
IOServiceGetMatchingServices(port, dict, &iter); | |
io_object_t device = 0; | |
while ((device = IOIteratorNext(iter))) | |
{ | |
CFMutableDictionaryRef result = NULL; | |
kern_return_t err = IORegistryEntryCreateCFProperties(device, &result, kCFAllocatorDefault, 0); | |
if (err == KERN_SUCCESS && result != NULL) { | |
CFTypeRef forceEnabled = NULL; | |
CFDictionaryGetValueIfPresent(result, CFSTR("ForceSupported"), &forceEnabled); | |
if (forceEnabled) { | |
NSLog(@"Force touch is supported!"); | |
} | |
} | |
IOObjectRelease(device); | |
} | |
IOObjectRelease(iter); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment