Using the Mouse Class
The mouse class consists of three types of properties:
Read-only properties: The Buttons property returns the number of buttons on the mouse, and the WheelPresent property returns whether the mouse includes a middle wheel. To use these (and other read-only) properties, simply retrieve the return value. For example, to use the MousePresent property, you might write code like this:
Dim oMouse As New Mouse If Not oMouse.MousePresent Then MsgBox "You must have a mouse to use this application." End If
Write-only properties: Actually, there's but one of these misbegotten, poorly conceived properties: the DoubleClickTime property. To retrieve this value, you'll need to inspect the HKEY_CURRENT_USER\Control Panel\Mouse\DoubleClickSpeed Registry entry. We could have added the appropriate code to this class, but to do so would have involved borrowing code from Chapter 10. If you need to both set and retrieve this value, you may want to import the necessary classes from that chapter and retrieve the Registry setting in a Property Get procedure.
Read/Write properties: Properties such as MouseButtonSwap, CursorOn, and SnapToDefault are all read/write properties that accept and return Boolean values. Others, such as MouseSpeed, DragX, and MouseTrails, all accept and return long integers. In all these cases, you use the properties the same way you use properties of any object. For example, to cause the mouse to swap its buttons (the right-hand button becomes the main button, popular among left-handed users), use code like this:
Dim oMouse As New Mouse oMouse.MouseButtonSwap = True
The MouseSpeed and Related Properties
The only group of properties that requires any special explanation is the set of three properties: MouseSpeed, MouseThreshold1, and MouseThreshold2. These three work together to control how quickly the mouse cursor moves across the screen as you move the mouse physically. The MouseSpeed parameter can take on values between 0 and 2, representing the speed of the mouse cursor relative to the distance you've moved the mouse. The MouseThreshold (1 and 2) properties can take on values between 0 and 12. The following paragraphs explain how these three properties are related.
As you may have noticed, the more quickly you move the mouse, the further the mouse cursor moves on the screen. This means you don't have to lift the mouse and reposition it as often as you might otherwise have to. Windows uses three values to calculate the distance it will move the mouse cursor every time you move the mouse, based on two tests.
At measured time intervals, as you move the mouse, Windows polls the position of the mouse and the speed at which you're moving it. If, during one interval, the distance along either the x or y axis is greater than the first mouse threshold value (MouseThreshold1) and the mouse speed (MouseSpeed) is not 0, Windows doubles the distance. If the distance along either the x or y axis is greater than the second mouse threshold value and the mouse speed is 2, the operating system doubles the distance that resulted from applying the first threshold test. It is thus possible for the operating system to multiply relatively specified mouse motion along the x or y axis by up to four times.
If you use the Mouse Control Panel applet, you'll see only a single linear slider control to manage the mouse speed. Windows takes the seven possible settings on the slider and converts them into preset values for the three properties. Table 9.14 lists these preset triplets of values, starting with the slowest and ending with the fastest setting. Figure 9.13 shows the Mouse Control Panel applet, with the first, middle, and last MouseSpeed triplets pointed out.
Table 9.14: Preset Values for the Three Mouse Parameters
Figure 9.13: Mouse Control Panel applet, showing MouseSpeed triplets
Therefore, the MouseSpeed parameter controls the general speed of the mouse. As you move the mouse, if the MouseSpeed parameter is greater than 0 and the mouse is moved more physical units than the value specified in Threshold1, Windows doubles the distance, and the cursor moves farther. If the MouseSpeed is 2 and the distance moved was also greater than the value in the MouseThreshold2 parameter, Windows again doubles the distance. You can see that it makes no sense to have both the MouseSpeed parameter set to 1 and the Threshold2 parameter set to anything except 0—Windows will never even look at the Threshold2 value in that case.
If you intend to set these values, here are some general rules to help you:
If the MouseSpeed parameter is set to 0, Windows never looks at the Threshold values, and they should both be set to 0.
If the MouseSpeed parameter is set to 1, Windows never looks at the Threshold2 parameter, and it should be set to 0.
If MouseSpeed is set to 1, then the smaller Threshold1 is, the faster the mouse will move. This is why the Threshold1 values in Table 9.14 decrease from top to bottom while MouseSpeed stays at 1.
If MouseSpeed is set to 2, then the value of MouseThreshold2 becomes significant, but it should never be less than the MouseThreshold1 value. MouseThreshold2 is used only if the mouse has moved farther than the value in MouseThreshold1, so having a value that's smaller than the MouseThreshold1 value won't add any speed.
Therefore, if your MouseSpeed, MouseThreshold1, and MouseThreshold2 values are (0, 0, 0), there's no acceleration as you move the mouse. As long as the first value is 0, Windows never even looks at the next two.
If the values are (1, 10, 0) and:
You move the mouse 8 units, the cursor moves 8 units
You move the mouse 11 units, you've crossed the threshold, and Windows doubles the cursor movement to 22 units
If the values are (2, 4, 6) and:
You move the mouse 3 units, the cursor moves 3 units.
You move the mouse 5 units, you've crossed the first threshold, and Windows doubles the movement to 10 units for the cursor.
You move the mouse 7 units, you've crossed both thresholds, so Windows doubles the distance twice, moving the cursor 28 units.
As you can see, it's important to understand the relationship between the movement of the mouse and the MouseSpeed, MouseThreshold1, and MouseThreshold2 parameters in controlling the speed and acceleration of the mouse cursor.