Solved

How to change the mouse speed from VB

Posted on 2000-03-06
9
933 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 76
How to compare ms sql hashbytes results within vb6 5 73
How to measure sizes and angles in scanned images ? 3 63
VB6 ListBox Question 4 44
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

770 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