Solved

How to change the mouse speed from VB

Posted on 2000-03-06
9
919 Views
Last Modified: 2008-03-06
I am building an app where I want to provide an option for the user to change the mouse speed, for more precise cursor control. This can be done in Windows Settings. How can I do this from VB code, eg using an API?
0
Comment
Question by:awnelson
  • 5
  • 3
9 Comments
 
LVL 12

Expert Comment

by:roverm
ID: 2587498
u can use the SystemParametersInfo API.

D'Mzzl!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
ID: 2587509
to be exact:
use the SPI_SETMOUSESPEED parameter to set it to slow (1) or fast (20) (default = 10).

Good luck!

D'Mzzl!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
ID: 2587775
Here's an example code for NT:

Place a TextBox and a CommandButton on a form, then paste this code:

Private Const SPIF_SENDWININICHANGE = &H2
Private Const SPI_SETMOUSE = 4
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 Sub Command1_Click()
    If SystemParametersInfo(SPI_SETMOUSE, 0, CLng(Text1), SPIF_SENDWININICHANGE) <> 0 Then
        MsgBox "speed changed"
    Else
        MsgBox "speed not changed"
    End If
End Sub

Enter a value in Text1 (textbox) between 1 and 20 and press Command1.

If you're using w98, change the SPI_SETMOUSE to SPI_SETMOUSESPEED (see API viewer for value).
0
 

Author Comment

by:awnelson
ID: 2591516
I am using w95 and have not been able to get this to work as yet. VB5 crashes when I try to run it. On msdn I found the following: "Sets the two mouse threshold values and the mouse speed. The pvParam parameter must point to an array of three integers that specifies these values." Should pvParam be set an array, and if so what are typical values?
Grateful for further help.
ANelson
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:roverm
ID: 2591780
Try this:

Type pvParm
  pvParm1 As Integer
  pvParm2 As Integer
  pvParm3 As Integer
End Type

Private Sub Command1_Click()
Dim Parms As pvParm

    Parms.pvParm1 = CInt(Text1)

    If SystemParametersInfo(SPI_SETMOUSE, 0, Parms, SPIF_SENDWININICHANGE) <> 0 Then
        MsgBox "speed changed"
    Else
        MsgBox "speed not changed"
    End If
End Sub

Now its pointing to an array of 3 integers. You have to expiriment with which parm to use (pvParm1..3).

Good luck!
D'Mzzl!
RoverM
0
 

Author Comment

by:awnelson
ID: 2598469
Thanks for additional help
I was able to get this to work by using the array as you suggested. The mouse sensitivity changed by about 50%, (which is enough to be irritating, but not really useful) but not nearly as much as by using the windows settings options. Any further ideas?
A Nelson
0
 
LVL 12

Accepted Solution

by:
roverm earned 200 total points
ID: 2599987
Try the other parameters!
This is the API that the Control Panel uses ! So it should do the same!

D'Mzzl!
RoverM
0
 

Author Comment

by:awnelson
ID: 2607580
This does work, but I still can't adjust the speed as much as with the windows settings control. I wonder if it uses some additional API?
ANelson
0
 

Expert Comment

by:mountykit
ID: 2747010
listen
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now