Skip to content

Instantly share code, notes, and snippets.

@EthanArbuckle
Created December 20, 2015 19:00
Show Gist options
  • Save EthanArbuckle/d19ae06f1b880174c863 to your computer and use it in GitHub Desktop.
Save EthanArbuckle/d19ae06f1b880174c863 to your computer and use it in GitHub Desktop.
Detect if force touch is supported through IOKit
#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