J Cardinal
October 8th, 1999, 01:28 PM
Does anyone have any idea how to programatically modify the mouse speed through code? There is a way to do this through SystemParametersInfo (SPI_GETMOUSESPEED, SPI_SETMOUSESPEED) but the documentation states it only works with "Windows NT 5.0 and later, Windows 98"(does not work with win98, I tried).
I need something that will work with any win32 system. Mouse threshholds and acceleration are available through this function (SPI_GETMOUSE) for <NT5 but not the speed. Any help would be greatly appreciated.
Aaron Young
October 8th, 1999, 11:11 PM
You can use the SPI_GETMOUSE Param with the SystemParametersInfo API, it returns an array of 3 Long Values, specifying the Speed Threshold and Velocity, setting these in the right combination adjusts the speed of the Mouse, here's an example to demonstrate:
Place a Horizontal Scrollbar, (hscSpeed), on the Form with 2 Command Buttons, (cmdGetMouse & cmdSetMouse)..
private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (byval uAction as Long, byval uParam as Long, byref lpvParam as Any, byval fuWinIni as Long) as Long
private Const SPI_GETMOUSE = 3
private Const SPI_SETMOUSE = 4
private Const SPIF_SENDWININICHANGE = &H2
private Const SPIF_UPDATEINIFILE = &H1
private Sub cmdSetMouse_Click()
Dim lMouse(2) as Long
If hscSpeed > 3 then
lMouse(0) = 4
lMouse(1) = 3 * (8 - hscSpeed)
lMouse(2) = 2
else
If hscSpeed then
lMouse(0) = 13 - (3 * hscSpeed)
lMouse(1) = 0
lMouse(2) = 1
else
lMouse(0) = 0
lMouse(1) = 0
lMouse(2) = 0
End If
End If
Call SystemParametersInfo(SPI_SETMOUSE, 0&, lMouse(0), SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
cmdGetMouse_Click
End Sub
private Sub cmdGetMouse_Click()
Dim lMouse(2) as Long
Call SystemParametersInfo(SPI_GETMOUSE, 0&, lMouse(0), 0&)
If lMouse(1) then
hscSpeed = 8 - (lMouse(1) / 3)
else
If lMouse(0) then
hscSpeed = 4 - ((lMouse(0) - 1) / 3)
else
hscSpeed = 0
End If
End If
End Sub
private Sub Form_Load()
hscSpeed.Max = 6
cmdGetMouse_Click
End Sub
I've tested this code successfully on Win95, Win98 and WinNT 4.0 Platforms.
Aaron Young
Analyst Programmer
adyoung@win.bright.net
aarony@redwingsoftware.com