How to | Connect a Gamepad or Other Device to the Wolfram System

Beyond using a keyboard or mouse, you can control the Wolfram System with a joystick, gamepad, 3D mouse, or any device that follows the industry-standard human interface device specification.

To connect a new device to the Wolfram System, make sure that it is plugged in and turned on if necessary. If the device came with special drivers, make sure they are installed.

Any device that follows the industry-standard human interface device (HID) specification will be immediately available to the Wolfram System.

All of the devices detected by the Wolfram System are listed in the output of ControllerInformation[]. There are several built-in devices here in addition to a Logitech Dual Action gamepad that is connected via USB:

Once your device is detected, the Wolfram System is ready to use it.

    

By default, gamepads and other controllers can be used with Wolfram Language functions like Manipulate and Graphics3D. For instance, you can use a connected gamepad to adjust Manipulate controls or rotate 3D graphics with no additional configuration. For more information, see How to: Use Built-in Gamepad Support.

At a lower level, the Wolfram System allows any of the information visible in the output of ControllerInformation[] to be used with ControllerState[].

Here, the state of every control on the gamepad is returned as a list of rules:

The names of the controls in this list, like "Hatswitch X Axis", are taken directly from low-level information returned by the device.

Devices from different manufacturers often use different names for controls. The Wolfram System attempts to standardize these names to "X", "Y", "X2", "Y2", and so on for one-dimensional analog controls, and "B1", "B2", and so on for buttons.

To see how the Wolfram System maps its standardized names onto the hardware names, use "Mapping" with the controller name in ControllerState. Short is used here to display only a few lines of this mapping:

Here, the standardized names "X", "Y", and "Z" are used in a list to get the current state of the first three one-dimensional analog axes:

If you wrap this input with Dynamic, the output will update continuously, thus letting you view the state of each axis in real time.

For information on using these standardized names in functions like Manipulate, see How to: Use Built-in Gamepad Support.

    

If ControllerState does not immediately respond to your controller, you may need to adjust the ControllerPath option. Similar to the way the Wolfram System searches the directories in $Path when it looks for files, ControllerState searches for available controllers based on the ControllerPath setting.

The default setting for ControllerPath is to use gamepads, if any are present:

Because of this, you can omit "Logitech Dual Action" as the first argument to ControllerState and get the same result:

If there are no gamepads connected, then ControllerState by default will fall back to other joystick devices, 3D mice, and finally other controller devices, including infrared controllers and digitizers.

By changing the order of devices that appear in ControllerPath, you can change the order they are searched for by ControllerState.

Here, a preference for the sudden motion sensor that is built into some portable computers is specified in ControllerPath: