-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.m
103 lines (83 loc) · 2.86 KB
/
main.m
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#import <Foundation/Foundation.h>
#import <IOKit/hidsystem/IOHIDLib.h>
#import <stdio.h>
int get()
{
NXEventHandle handle = MACH_PORT_NULL;
io_service_t service = MACH_PORT_NULL;
mach_port_t masterPort;
CFTypeRef typeRef = NULL;
CFNumberRef number = NULL;
unsigned int acceleration;
kern_return_t res = IOMasterPort(MACH_PORT_NULL, &masterPort);
if (res == KERN_SUCCESS)
service = IORegistryEntryFromPath(masterPort, kIOServicePlane ":/IOResources/IOHIDSystem");
if (res == KERN_SUCCESS && service)
res = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &handle);
if (res == KERN_SUCCESS)
res = IOHIDCopyCFTypeParameter(handle, CFSTR(kIOHIDMouseAccelerationType), &typeRef);
if (res == KERN_SUCCESS)
{
number = (CFNumberRef)typeRef;
CFNumberGetValue(number, kCFNumberSInt32Type, &acceleration);
CFRelease(typeRef);
IOObjectRelease(service);
printf("Acceleration is %d\n", acceleration);
}
return 0;
}
int set()
{
NSInteger value = -65536;
CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberNSIntegerType, &value);
CFMutableDictionaryRef propertyDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, NULL, NULL);
CFDictionarySetValue(propertyDict, @"HIDMouseAcceleration", number);
io_connect_t connect;
io_service_t service = IORegistryEntryFromPath(kIOMasterPortDefault, kIOServicePlane ":/IOResources/IOHIDSystem");
kern_return_t res = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &connect);
if (!connect || res != KERN_SUCCESS)
printf("Unable to open service\n");
else
{
res = IOConnectSetCFProperties(connect, propertyDict);
if (res != KERN_SUCCESS)
printf("Failed to set mouse acceleration\n");
else
printf("Acceleration set to %ld\n", value);
}
IOServiceClose(connect);
IOObjectRelease(service);
CFRelease(propertyDict);
return 0;
}
void loop()
{
sleep(15);
while (true)
{
set();
sleep(3);
}
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
if (argc <= 1)
{
printf("fixmouse - macOS mouse acceleration killer v1.0\n");
printf("(c) 2019 Patrick Jane - https://github.com/patrickjane/fixmouse\n");
printf("Usage:\n");
printf(" $ fixmouse [command]\n");
printf("Commands:\n");
printf(" get - retrieves the current mouse acceleration and prints it to console\n");
printf(" set - kills mouse acceleration once\n");
printf(" loop - kills mouse acceleration repeatedly (program will not terminate)\n");
return 1;
}
if (!strcmp(argv[1], "get"))
return get();
if (!strcmp(argv[1], "set"))
return set();
loop();
}
return 0;
}