[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to change the mouse speed from VB

Posted on 2000-03-06
9
Medium Priority
?
1,140 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

834 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