Solved

How to change the mouse speed from VB

Posted on 2000-03-06
9
1,033 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…

695 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