How can I print the Joystick click to the console via the JInput library?

119 views Asked by At

I am working on Java map project. I use the Logitech extreme 3D pro Joystick and JInput library. I want to write text to the console when the buttons on the joystick are clicked. But I can't do that, can anyone help?

1

There are 1 answers

0
MWiesner On

You can adapt the JInput example found here which shows "how to read the values in a polling loop for the first mouse". In line 28 simply change the controller type to STICK, as it is defined in the Controller class of that library:

/**
 * Stick controller, such as a joystick or flightstick.
 */
public static final Type STICK = new Type("Stick");

If you execute the example you will retrieve "the components of the controller" (see line 46, /* Get all the axis and buttons */).

With those components at hand, you can retrieve properties or data from the connected (joystick) controller, in your case not a mouse but a joystick.

Hint: Before modifying the example, you can just start to experiment with the "first mouse" connected to your machine.