Tired of Mac OS X's mouse acceleration?

Everything todo with programming goes HERE.
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Tired of Mac OS X's mouse acceleration?

Post by Jonathan »

Needs CoreFoundation and IOKit:

Code: Select all

#include <stdio.h>
#include <IOKit/hidsystem/IOHIDLib.h>
#include <IOKit/hidsystem/IOHIDParameter.h>
/* didn't really sort the headers out, but it compiles and runs here */

int main(int argc, char **argv) {
	const uint32_t accel = 0x80000000; /* signed 2's complement (probably) (using unsigned for setting-bits-by-hand reasons) 16.16 fixed point; normally non-negative, otherwise all acceleration and scaling will be disabled */
	io_connect_t handle = NXOpenEventStatus(); /* NXEventHandle and io_connect_t are the same thing */
	if(handle) {
		if(IOHIDSetParameter(handle, CFSTR(kIOHIDMouseAccelerationType), &accel, sizeof accel) != KERN_SUCCESS) {
			printf("Failed to set mouse accel\n");
		}
		if(IOHIDSetParameter(handle, CFSTR(kIOHIDTrackpadAccelerationType), &accel, sizeof accel) != KERN_SUCCESS) {
			printf("Failed to set trackpad accel\n");
		}
		NXCloseEventStatus(handle);
	} else {
		printf("No handle\n");
	}
	return 0;
}
This maps mouse units directly to pixels. If you have the right resolution and stable readings, this could work very well. Bear in mind that this is probably unsupported, but it works for me on 10.4.6, unlike a deprecated solution.

Some ways to revert to your old settings:
- Set a different accel in this code.
- Log out and back in.
- Use the preference pane you're used to.
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

It's been a while, but

Code: Select all

defaults write .GlobalPreferences com.apple.mouse.scaling -1
defaults write .GlobalPreferences com.apple.trackpad.scaling -1
works as well. Run the above in Terminal.app, log out, and then back in. If it didn't work something else has probably touched the file. That's unlikely to happen shortly after a clean login, so just do it again. If you succeed, don't be afraid to change mouse settings in System Preferences. It'll be left at -1 as long as you don't touch the speed slider.
phero
Posts: 4
Joined: Sat Apr 26, 2008 3:10 pm

Re: Tired of Mac OS X's mouse acceleration?

Post by phero »

Jonathan wrote:Needs CoreFoundation and IOKit:

Code: Select all

#include <stdio.h>
#include <IOKit/hidsystem/IOHIDLib.h>
#include <IOKit/hidsystem/IOHIDParameter.h>

...
[/quote]

Hey Jonathan, thanks for posting this.

I just got a macbook. Coming from Windows however, I am really annoyed with OSX's mouse acceleration. I'm currently using USBOverdrive, however it does not completely fix the problem. The two terminal commands you gave seem to work, but they also drop tracking speed to the lowest, which makes it a less preferable solution.

Anyway, being a total programming newbie, I was wondering how I can apply your first fix to my macbook? Assuming it completely removes the acceleration (in other words, giving a pure 1:1 ratio). I tried finding some info on how to use IOKit and CoreFoundation, but it's really out of my league. Could you perhaps explain to me the steps I need to go through to apply this fix?

If it's too much trouble I understand. I would be really grateful though.. I don't understand why it's so hard to fix this problem and why Apple does not enable you to simply turn it off.

Thanks in advance for any help.

phero
User avatar
wrtlprnft
Reverse Outside Corner Grinder
Posts: 1679
Joined: Wed Jan 04, 2006 4:42 am
Location: 0x08048000
Contact:

Post by wrtlprnft »

/me doesn't get why someone would want a touchpad without mouse acceleration.
There's no place like ::1
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

wrtlprnft wrote:/me doesn't get why someone would want a touchpad without mouse acceleration.
The one in my PowerBook still allows me to swipe across the majority of the screen. And I can target single pixels. I 'roll' my finger over the pad a bit for minor adjustments, if that means anything.

Anyway, it seems that 10.5 broke this trick. When you set a negative value you get zero instead, which removes acceleration, but is terribly slow. Maybe the programmatic way still works (edit: it does! :D); I only tried hacking the preferences file so far on 10.5.
ˌɑrməˈɡɛˌtrɑn
phero
Posts: 4
Joined: Sat Apr 26, 2008 3:10 pm

Post by phero »

wrtlprnft wrote:/me doesn't get why someone would want a touchpad without mouse acceleration.
Well it wouldn't be for the touchpad, but for the USB mouse I have attached to my macbook ;)
phero
Posts: 4
Joined: Sat Apr 26, 2008 3:10 pm

Post by phero »

Jonathan wrote:
wrtlprnft wrote:/me doesn't get why someone would want a touchpad without mouse acceleration.
The one in my PowerBook still allows me to swipe across the majority of the screen. And I can target single pixels. I 'roll' my finger over the pad a bit for minor adjustments, if that means anything.

Anyway, it seems that 10.5 broke this trick. When you set a negative value you get zero instead, which removes acceleration, but is terribly slow. Maybe the programmatic way still works (edit: it does! :D); I only tried hacking the preferences file so far on 10.5.
Is there any easy way to explain this "hacking" to a programming newbie? I'd do anything to get rid of the acceleration completely.
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

Here's a little tool for non-programmers.

Source file:

Code: Select all

#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;
}
To run it, unpack the tgz, open Terminal, drop killmouseaccel on it, type mouse and/or trackpad, separated by spaces, and hit enter. Should look like this:

Code: Select all

/Users/jonathan/Desktop/killmouseaccel mouse trackpad
Note that it won't last; you have to run it again after setting mouse accel with something else or after logging in again.

Compiled for 10.4 universal, if it matters to anyone.
Attachments
killmouseaccel.tar.gz
(3.65 KiB) Downloaded 11429 times
ˌɑrməˈɡɛˌtrɑn
phero
Posts: 4
Joined: Sat Apr 26, 2008 3:10 pm

Post by phero »

You're my new hero, Jonathan!

You know a lot of people actually buy USBOverdrive just for killing the mouse accel, right? This fixes it without any third party software.

However, just like with USBOverdrive, I'm not 100% sure this fix completely removes any acceleration. On the other hand, maybe I'm just being paranoid.

In any case, thanks a lot for your help.

Edit: It's still there in World of Warcraft, but I'm quitting that game anyway - it runs crap on a macbook.
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

Here's an attempt at a GUI. Not my specialty but it seems to work. :) Should be more convenient for most.

All copyright notices I found that it put in automatically were removed deliberately; I don't care.

phero: glad to be of help. :) I clearly felt that MouseFix didn't work, but here I clearly feel it does. And no matter how fast or slow I move, the pointer always moves the same distance with the same mouse movement. Try for yourself: move the pointer to the edge of the screen, and move the mouse say 3 cm at high speed. Then try again at low speed. Move back and forth a bit but finish in the same spot (make sure you don't clip the pointer at the edge of the screen). Is there a significant difference in the final pointer position?

I don't know why it doesn't work in WoW. Maybe it sets mouse accel itself, applies its own, or just feels bad because it doesn't run too well ("mouse lag" but not accel).
Attachments
Kill Mouse Accel.dmg.gz
Really gzipped. Xcode project included.
(92.8 KiB) Downloaded 9658 times
ˌɑrməˈɡɛˌtrɑn
User avatar
Al's Used Cars
On Lightcycle Grid
Posts: 45
Joined: Sun Dec 03, 2006 3:22 pm
Location: Baltimore, MD

Post by Al's Used Cars »

http://www.versiontracker.com/dyn/moreinfo/macosx/12205


this freeware app works well for me as far as making the mouse & trackpad controllable. If you read the docs for this app, it does sound like what Jonathan has done, without the scaling tinkering. The author says the source is available, so... get it and stick a mod in there.

I dont really get the issue with the mouse accel. I'm using 10.3.9 - maybe it was changed in Tiger or Leopard.
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

With MouseZoom you only get more acceleration. It changes the same variable but only allows an entirely different range.
ˌɑrməˈɡɛˌtrɑn
User avatar
Ratchet
Match Winner
Posts: 779
Joined: Sat Mar 15, 2008 5:55 am

Post by Ratchet »

Not to be nitpicky, but Ubuntu seems to have supercharged touch pad speeds itself, I tried that and lost my mouse pointer... guess I'll stick to wireless mouse..
cjd888
Posts: 1
Joined: Thu Sep 18, 2008 12:16 pm

Post by cjd888 »

Thank you that works really well, but I would like to be able to increase the scaling as the default is a bit slow for me. Do I just change the accel variable? and how do I compile this? I have xcode but I'm new to MAC development and not sure how to setup the project etc

sorry i'm being an idiot the xcode project is included with the download :oops:
tatuman
Posts: 1
Joined: Thu Jan 22, 2009 9:13 pm

Post by tatuman »

Thanks so much Jonathan for this!

I was finding it super annoying to use the mouse in my new mac, and I tried everything, 5 or 6 different mouses, also tried different mac, etc, and the problem remained the same. Still I think that the mouse does not respond as well as in Windows. I have been a windows user for 15 years, and when I use a mouse, I usually use fast movements to the place I want to reach, and then I very precise slow movements to reach the final destination, but it seems that under MAC OSX these small movements are not perceived by system as well as in WIN and it lags a bit. If i do very small circles on my windows machine it detects it perfectly, while on mac it doesnt, it is like it is lagging a bit, like if it stutters, does anyone share the same feelings? Is there a way to improve this small movements? Btw, this is already using your fix!

Thanks
Post Reply