Changing mouse sensitivity on the fly.

Windows specific forum
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Changing mouse sensitivity on the fly.

Post 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!
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

I think I just found what I need in the SystemParametersInfo API function...

/me runs off to "play"... :mrgreen:
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post by Matt »

Please share?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Matt wrote:Please share?

Code: Select all

MouseAccel = 10 ; Maximum = 20

SystemParametersInfo_(#SPI_SETMOUSESPEED,0,MouseAccel,0)
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post 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
Last edited by Tipperton on Sun Apr 01, 2007 12:14 am, edited 1 time in total.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post 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)
Last edited by Tipperton on Tue Apr 03, 2007 12:44 am, edited 1 time in total.
Clutch
User
User
Posts: 52
Joined: Sun Nov 26, 2006 6:11 am
Location: South Florida

Post 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. :)
"Ahead one third... ahead two thirds... Full ahead flank
And out from the belly of the whale came a prophet, Amen"
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post 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:
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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).
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post 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
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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.
Post Reply