The return value of SystemParametersInfo()
is a BOOL
, aka an alias for a 4-byte int
. So use int
instead of boolean
on the Java side for the return value.
That aside, the reason SystemParametersInfo()
is failing is because you are not passing in the speed value correctly. Read the SPI_SETMOUSESPEED
documentation carefully:
SPI_SETMOUSESPEED
0x0071
Sets the current mouse speed. The pvParam parameter is an integer between 1 (slowest) and 20 (fastest). A value of 10 is the default. This value is typically set using the mouse control panel application.
Compare that to the SPI_GETMOUSESPEED
documentation:
SPI_GETMOUSESPEED
0x0070
Retrieves the current mouse speed. The mouse speed determines how far the pointer will move based on the distance the mouse moves. The pvParam parameter must point to an integer that receives a value which ranges between 1 (slowest) and 20 (fastest). A value of 10 is the default. The value can be set by an end-user using the mouse control panel application or by an application using SPI_SETMOUSESPEED.
So, even though the pvParam
parameter is declared as a pointer, SPI_SETMOUSESPEED
wants the actual integer value, not a pointer to an integer that holds the value, like you are currently passing by using IntByReference.getPointer()
. This is confirmed in the answer to this question (though for C++, not Java):
Mouse speed not changing by using SPI_SETMOUSESPEED
In C/C++, the solution is like this:
SystemParametersInfo(SPI_SETMOUSESPEED, 0,
(void*)2,
SPIF_UPDATEINIFILE | SPIF_SENDCHANGE | SPIF_SENDWININICHANGE);
In Java, the equivalent is more like this:
User32.INSTANCE.SystemParametersInfo(SPI_SETMOUSESPEED, 0,
Pointer.createConstant(2),
SPIF_UPDATEINIFILE | SPIF_SENDCHANGE | SPIF_SENDWININICHANGE);