Solved

How to change the mouse speed from VB

Posted on 2000-03-06
9
900 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
Comment Utility
u can use the SystemParametersInfo API.

D'Mzzl!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 12

Expert Comment

by:roverm
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
listen
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

10 Experts available now in Live!

Get 1:1 Help Now