Joystick Mouse
This example will demonstrate how to make the mini-joystick on a CH Products CH Pro Throttle USB act like a mouse. This example assumes that you are familiar with the basics of creating Building Blocks.
The basic steps to accomplish this task will be:
- Create a virtual mouse
- Create calibrated mouse axis values from the joystick axes
- Connect the calibrated mouse axis values to the virtual mouse
The first task is to create a virtual mouse. Select the “Virtual Controllers” button in the Editor window and click the
button. A new virtual mouse will appear in the Directory panel and in the Palette window’s list of devices. The default settings for the new virtual mouse will be sufficient for this example.
The second task is to link the axes from the mini-joystick to the axes of the virtual mouse. In order to do so, the values from the joystick axes must first be converted into values that mimic mouse axes. Create the building blocks which represent the joystick axes and add a Axis Calibration building block to each:
A joystick axis generally has a value in the range 0...255 and has a value of about 128 when centered. A mouse axis generally has a value in the range -40...40 and has a value of 0 when motionless. The Axis Calibration building blocks need to be configured to convert the joystick axis values into mouse axis values.
First, change the calibrated output range values to -5 and 5:
The size of the output values will affect the speed of the cursor on the screen. Larger numbers cause the cursor to move faster. It is important that the two output values have same size and opposite signs. This results in symmetric mouse movement and a center value of “0” (no movement).
Next, if the joystick axis is not capable of reaching its minimum and maximum values, then the input value range on the Axis building block needs to be adjusted. For the lower limit, move the joystick axis to its lowest value, observe the red mark in the range control, then move the left blue arrow to match the red mark. Repeat for the upper limit by moving the joystick axis to its highest value and adjusting the right blue arrow. The smallest value that the X-Axis used in this example creates is “33”, the largest value it creates is “235”.
Next, if the joystick axis does not have a value of 128 when centered, then adjust the center value. Let the joystick return to its center position, then drag the red arrows to align with the red mark in the range control. If the red arrows are obscured by the gray arrows (deadband arrows), then the center point can be moved by clicking and dragging between the red arrows. The X-Axis used in this example has a value of “135” when it is centered.
Last, if the joystick axis doesn’t always return to the same center point, or if it has a “loose” feel near the center point, then the size of the deadband can be increased. The deadband creates an area in the middle of the joystick’s movement that is treated as the “center position”. A joystick axis which is very accurate and always returns to the same center position may allow for a small deadband value. A joystick axis which is “loose” near its center position may require a larger deadband value. The size of the deadband will mostly depend upon the user’s preference. Adjust the deadband by dragging a gray arrow as necessary.
At this point, the axis should be calibrated correctly. If you move the axis to one limit, you should see “5” at the output of the Axis Calibration building block. If you move the axis to the other limit, you should see “-5” at the output. When the axis is centered, the output should be “0”.
Repeat this process for both the X and Y axes.
The final step is to connect the newly calibrated joystick axes to the Virtual Axis building blocks which represent the axes of the virtual mouse.
Now, when the joystick axes are moved, the cursor should move around on the screen. To adjust the speed of the cursor, adjust the calibrated output range of the Axis Calibration building blocks.
If you are using Mac OS X 10.4 or newer, you can also use a Controller Configuration to customize the speed of the cursor. A custom mouse acceleration curve can be created for a virtual mouse in the same manner as a normal mouse. If a custom acceleration curve is used, then using -40...40 as the output range of the Axis Calibration building blocks will give you the best resolution for your custom acceleration curve.
