Skip to content

Instantly share code, notes, and snippets.

@twslankard
Created September 28, 2011 18:43
Show Gist options
  • Save twslankard/1248841 to your computer and use it in GitHub Desktop.
Save twslankard/1248841 to your computer and use it in GitHub Desktop.
disable mouse acceleration on mac os x
/**
* to build: gcc -o mousekiller mousekiller.c -framework CoreFoundation -framework IOKit
*/
#include <stdio.h>
#include <IOKit/hidsystem/IOHIDLib.h>
#include <IOKit/hidsystem/IOHIDParameter.h>
int main(int argc, char **argv)
{
const int32_t accel = -0x10000; // if this ever becomes a scale factor, we set it to one
if(argc < 2) {
fprintf(stderr, "Give me mouse and/or trackpad as arguments\n");
return 1;
}
io_connect_t handle = NXOpenEventStatus();
if(handle) {
int i;
for(i=1; i<argc; i++) {
CFStringRef type = 0;
if(strcmp(argv[i], "mouse") == 0)
type = CFSTR(kIOHIDMouseAccelerationType);
else if(strcmp(argv[i], "trackpad") == 0)
type = CFSTR(kIOHIDTrackpadAccelerationType);
if(type && IOHIDSetParameter(handle, type, &accel, sizeof accel) != KERN_SUCCESS)
fprintf(stderr, "Failed to kill %s accel\n", argv[i]);
}
NXCloseEventStatus(handle);
} else
fprintf(stderr, "No handle\n");
return 0;
}
@twslankard
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment