Page 1 of 1

Changing mouse sensitivity on the fly.

Posted: Sat Mar 31, 2007 8:08 pm
by Tipperton
Here's a challenge for a Windows guru....

A game I'm playing has its mouse sensitivity set too high for me. Unfortunately the game developer didn't provide a setting to adjust this.

So I'm writing a small launcher for the game. The idea is to have the launcher lower the system's mouse sensitivity adjustment, run the game, then restore the sensitivity setting after the game exits.

I've already found where in the registry the setting is store and have already written the program, all except for one thing...

As I suspected, it turns out that just changing the setting in the registry isn't enough. After changing the setting, I need a way to tell Windows to go get the new setting and start using it.

Anyone know how to do this?

Thanks!

Posted: Sat Mar 31, 2007 8:36 pm
by Tipperton
I think I just found what I need in the SystemParametersInfo API function...

/me runs off to "play"... :mrgreen:

Posted: Sat Mar 31, 2007 8:38 pm
by Matt
Please share?

Posted: Sat Mar 31, 2007 9:03 pm
by Fluid Byte
Matt wrote:Please share?

Code: Select all

MouseAccel = 10 ; Maximum = 20

SystemParametersInfo_(#SPI_SETMOUSESPEED,0,MouseAccel,0)

Posted: Sun Apr 01, 2007 12:02 am
by Tipperton
Matt wrote:Please share?
I will, or would have, once I had something working, no point sending you on one of my wild goose chases.... ;)

Where did you find that?

The info I have makes no mention of SPI_SETMOUSESPEED, all it has is SPI_GETMOUSE and SPI_SETMOUSE which didn't work.... :(

Never mind, as much as I don't like M$'s documentation, I found it in the MSDN Library I got with Visual Studio 6, guess I'll have to reload it and dump this old documentation I've been using.... :p

Posted: Sun Apr 01, 2007 12:12 am
by ts-soft

Posted: Sun Apr 01, 2007 12:42 am
by Tipperton
Hmm... must be something more to it than that....

Code: Select all

lNewSensitivity=1
SystemParametersInfo_(#SPI_SETMOUSESPEED, 0, @lNewSensitivity, #SPIF_SENDWININICHANGE)
Had no effect no matter what value lNewSensitivity has.

Ooops! Not a pointer for SET...

It works now.... :)

Correct code is:

Code: Select all

SystemParametersInfo_(#SPI_GETMOUSESPEED, 0, @lNewSensitivity, 0)
SystemParametersInfo_(#SPI_SETMOUSESPEED, 0, lNewSensitivity, #SPIF_SENDWININICHANGE)

Posted: Mon Apr 02, 2007 4:51 pm
by Clutch
Tipperton wrote:...
Microsoft's docs say that the third parameter has to be a pointer so I put the @ sign in there.

...
Notice that you need the @ when getting the parameters, but don't need it when you are setting them.... weird....
It's specified that way in the documentation:
MSDN docs for SPI_GETMOUSESPEED wrote:...
The pvParam parameter must point to an integer that receives a value ...
MSDN docs for SPI_SETMOUSESPEED wrote:...
The pvParam parameter is an integer between 1 (slowest) and 20 (fastest)...
Though I don't really understand why they wouldn't keep it consistent and also require a pointer for pvParam when setting the speed. Good ol' MS. :)

Posted: Mon Apr 02, 2007 11:53 pm
by Tipperton
Clutch wrote:Though I don't really understand why they wouldn't keep it consistent and also require a pointer for pvParam when setting the speed. Good ol' MS. :)
Ooops! :shock:

I only read the docs for SPI_GETMOUSESPEED and figured it would be consistant for SPI_SETMOUSESPEED.

Count on M$ to find ways to throw curve balls at us....

Anyway, although it worked, it only worked for part of the game, apparently in menued sections without a lot of animation they use the standard Windows mouse routines, but for the rest of the game that has a lot of animation, they use DirectInput which apparently ignores the system mouse settings.

Not even going to try setting the DirectInput sensitivity because the game probably would reset it to the value they chose when they initialize DirectInput....

Oh well.... If nothing else I learned a few things in this excercize so it wasn't a total loss. :mrgreen:

Posted: Tue Apr 03, 2007 12:03 am
by Fred
It's logical to not ask for a pointer when using SET, so you can pass the number directly (for example a constant or anything).

Posted: Sat Nov 22, 2008 6:30 pm
by Michael Vogel
Hm,
does anyone know, which of these two lines should be used...

Code: Select all

*MouseInfo=18
SystemParametersInfo_(#SPI_SETMOUSESPEED,#Null,*MouseInfo,#SPIF_SENDWININICHANGE) 
SystemParametersInfo_(#SPI_SETMOUSESPEED,#Null,*MouseInfo,#SPIF_UPDATEINIFILE) 
Michael

Posted: Sat Nov 22, 2008 11:23 pm
by Rescator
What game is it? Most games have a config file of sorts and you may be able to enter the sensitivity there. (then set the readonly flag on the file so the game can't change it) if lucky it will use the setting. (avoid changing the config in the game obviously).

Also, what mouse? If it's a Microsoft or Logitech or Saitek then they do have mouse apps that let you make profiles for your game(s) etc.
The Microsoft app (Intellimouse?) "might" also work on any Microsoft mouse compatible mouse.