Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure mouse enhance pointer precision programmatically

How to configure mouse enhance pointer precision programmatically in C++? I know that have some useful commands like SystemParametersInfo, for speed, ...

int x = 15;

SystemParametersInfo(SPI_SETMOUSESPEED, NULL, reinterpret_cast(x),SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );

... but I cannot find enhance precision----

like image 750
raptor Avatar asked May 23 '26 21:05

raptor


2 Answers

According to the documentation for the SystemParametersInfo function and SPI_SETMOUSE:

Sets the two mouse threshold values and the mouse acceleration. The pvParam parameter must point to an array of three integers that specifies these values. See mouse_event for further information.

So you need an array containing 3 values, and you specify a pointer to that array as the pvParam parameter when calling SystemParametersInfo.

Since all you care about is changing the acceleration (the last value), you probably want to retain the current values for the first two, the mouse threshold values. Do that by calling SystemParametersInfo with the SPI_GETMOUSE flag to obtain those values, then modifying the last one (the acceleration), and then calling SystemParametersInfo again, this time with the SPI_SETMOUSE flag.

Sample code (without recommended error checking):

// Turns mouse acceleration on/off by calling the SystemParametersInfo function.
// When mouseAccel is TRUE, mouse acceleration is turned on; FALSE for off.
void SetMouseAcceleration(BOOL mouseAccel)
{
    int mouseParams[3];

    // Get the current values.
    SystemParametersInfo(SPI_GETMOUSE, 0, mouseParams, 0);

    // Modify the acceleration value as directed.
    mouseParams[2] = mouseAccel;

    // Update the system setting.
    SystemParametersInfo(SPI_SETMOUSE, 0, mouseParams, SPIF_SENDCHANGE);
}

And you probably already know this, but there are too many badly-behaved applications out there for me not to mention it just in case. If you're doing this in your application, be sure to save the original value so that you can restore it when your app is closed! This is just basic etiquette when you're modifying system-wide settings.

like image 52
Cody Gray Avatar answered May 26 '26 11:05

Cody Gray


'Enhance pointer precision' is an on/off acceleration option.

The SPI_SETMOUSE parameter for SystemParametersInfo will adjust this setting.

I can't tell you exactly how the acceleration values are affected, but if you SPI_GETMOUSE and display the values with the setting on and off you will find it.

like image 23
Zooba Avatar answered May 26 '26 11:05

Zooba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!