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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…