To monitor these devices in LabVIEW you can use the built in Input Device VIs. These VIs allow you to monitor attached keyboards, mice, and joysticks. These VIs are found on the Connectivity>>Input Device Control
palette. The following example walks through how to read from a joystick input device, and the same process applies to mice and keyboards.
- Call Initialize Joystick.vi. In this VI, use the device index input to identify the device to be read from. This is a numeric value that corresponds to the device number given by the operating system. Use the corresponding Initialize VI if doing this for a different input device.
- Wire the device ID output from the Initialize Joystick.vi to the device ID input of Acquire Input Data.vi. For the joystick, this VI will give information such as the axis information, button status, and directional information that corresponds to the operations on the joystick or gamepad. This VI is polymorphic and will also return information for a mouse or keyboard if such a device ID is passed to it.
- Axis info: This cluster of numeric controls returns the joystick's rotating inputs.
- Button info: This cluster of boolean controls gives you the status of each one of the buttons in the joystick. Please note that they might not map the same way as they appear in your joystick.
- Direction info: Use this output for the joystick's Point of View (also called Point of View Hat) inouts.
- End with Close Input Device.vi. Wire the device ID output from the Acquire Input Data.vi to the device ID input of the Close Input Device.vi. This VI should be called at the completion of reading to close the reference to the device.
This method will work with Windows and Linux operating systems, but are not supported on MAC OS X.
If you would like to use the joystick to control a CompactRIO (cRIO), you will need to run the Joystick VIs on a host computer due to using external code that would not run on a cRIO system. This data could then be moved to the cRIO using a shared variable or alternative communication method
depending on the particular application.