-
Notifications
You must be signed in to change notification settings - Fork 2
/
iokit.c
49 lines (37 loc) · 1.74 KB
/
iokit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// iokit
#include "iokit.h"
static IOHIDEventSystemClientRef ioHIDClient;
static CFRunLoopRef ioHIDRunLoopSchedule;
void init_iokit(int checkInterval) {
ioHIDRunLoopSchedule = CFRunLoopGetMain();
int pv1 = 0xff00;
int pv2 = 4;
CFNumberRef vals[2];
CFStringRef keys[2];
vals[0] = CFNumberCreate(CFAllocatorGetDefault(), kCFNumberSInt32Type, &pv1);
vals[1] = CFNumberCreate(CFAllocatorGetDefault(), kCFNumberSInt32Type, &pv2);
keys[0] = CFStringCreateWithCString(0, "PrimaryUsagePage", 0);
keys[1] = CFStringCreateWithCString(0, "PrimaryUsage", 0);
CFDictionaryRef matchInfo = CFDictionaryCreate(CFAllocatorGetDefault(),(const void**)keys,(const void**)vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
ioHIDClient = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
IOHIDEventSystemClientSetMatching(ioHIDClient, matchInfo);
CFArrayRef matchingsrvs = IOHIDEventSystemClientCopyServices(ioHIDClient);
if (CFArrayGetCount(matchingsrvs) != 0) {
IOHIDServiceClientRef alssc = (IOHIDServiceClientRef)CFArrayGetValueAtIndex(matchingsrvs, 0);
int ri = checkInterval * 1000000;
CFNumberRef interval = CFNumberCreate(CFAllocatorGetDefault(), kCFNumberIntType, &ri);
IOHIDServiceClientSetProperty(alssc, CFSTR("ReportInterval"), interval);
}
}
void start_iokit(IOHIDEventSystemClientEventCallback callback) {
if (ioHIDClient) {
IOHIDEventSystemClientScheduleWithRunLoop(ioHIDClient, ioHIDRunLoopSchedule, kCFRunLoopDefaultMode);
IOHIDEventSystemClientRegisterEventCallback(ioHIDClient, callback, NULL, NULL);
}
}
void stop_iokit() {
if (ioHIDClient) {
IOHIDEventSystemClientUnregisterEventCallback(ioHIDClient);
IOHIDEventSystemClientUnscheduleWithRunLoop(ioHIDClient, ioHIDRunLoopSchedule, kCFRunLoopDefaultMode);
}
}