Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

c++ - 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----

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...