Re: Get / Set Mouse speed
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
[email protected]
[email protected]