Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
72 ratings:
 3.70 out of 5   

How Can I Monitor a Joystick, Keyboard, or Mouse in LabVIEW?



Primary Software:
Primary Software Version: 1.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
I have an application that uses a joystick, keyboard, and/or mouse. How can I monitor these input devices in LabVIEW?

Solution:
LabVIEW 7 introduced Input Device Control VIs. These VIs allow you to monitor attached keyboards, mice, and joysticks. These VIs are found on the All Functions»Advanced»Input Device Control palette in LabVIEW 7.x and on the Functions»Communications»Input Device Control palette in LabVIEW 8.x. In LabVIEW 2012, these VIs can be found on the Functions»Connectivity»Input Device Control palette. The following example walks through how to read from a joystick input device.  However, the same process applies to each type of input device.

  1. 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 in the operating system. Use the corresponding Initialize VI if doing this for a different input device, i.e. Initialize Mouse.vi.
  2. 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.
  3. End with Close Input Device.vi. Wire the device ID output from the Acquire Input Data.vi to the device ID input of Close Input Device.vi. This VI should be called at the completion of reading to close the reference to the device.


Figure 1: Joystick Position - Block Diagram

This method will work with Windows (if DirectX 8.0 or later is installed) and Linux operating systems. These VIs are not supported on a Mac OS.

In previous versions of LabVIEW, external code, such as the Windows winmm.dll, can be called to get data from the joystick or gamepad. An example of this method, created for LabVIEW 5.0.1 on Win32 machines, is linked to below.

An example of mouse monitoring can be found at Community: Monitoring Mouse Movements and Clicks.  An example of keyboard monitoring can also be found at Community: Monitoring of Keyboard Buttons that are Pressed.



Related Links:
Community: Monitoring Mouse Movements and Clicks
Community: Monitoring of Keyboard Buttons that are Pressed

Attachments:





Report Date: 10/31/2003
Last Updated: 01/16/2014
Document ID: 32UBKD28

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit