Acá les explico como se hace
Acá esta la clase que maneja los eventos
código
import java.io.IOException;
import com.centralnexus.input.Joystick;
import com.centralnexus.input.JoystickListener;
public class JoystickControl implements JoystickListener
{
//---------------------------------------------------------------
// MEMBERS
//---------------------------------------------------------------
// Class Constants
public final int UP = 0,
DOWN = 1,
LEFT = 2,
RIGHT = 3,
BUTTON1 = 0,
BUTTON2 = 1,
BUTTON3 = 2,
BUTTON4 = 3;
// Variable members
private Joystick pJoy;
private int nNumDevices;
private boolean abAxis[] = {false, false, false, false};
private boolean abButtons[] = {false, false, false, false};
//---------------------------------------------------------------
// CONSTRUCTOR
//---------------------------------------------------------------
public JoystickControl()
{
super();
this.pJoy = null;
this.nNumDevices = Joystick.getNumDevices();
if (this.nNumDevices > 0)
{
try
{
this.pJoy = Joystick.createInstance();
this.pJoy.addJoystickListener(this);
}
catch (IOException e)
{
e.printStackTrace();
this.pJoy = null;
}
}
}
//---------------------------------------------------------------
// Is Available
//---------------------------------------------------------------
public boolean isAvailable ()
{
return (this.pJoy != null);
}
//---------------------------------------------------------------
// getAxis (UP, DOWN, LEFT, RIGHT)
//---------------------------------------------------------------
public boolean getAxis (int nDir)
{
return isAvailable() && this.abAxis[nDir];
}
//---------------------------------------------------------------
// getAxisAlt (UP, DOWN, LEFT, RIGHT) resets the direction
//---------------------------------------------------------------
public boolean getAxisAlt (int nDir)
{
boolean bRet = isAvailable() && this.abAxis[nDir];
if (bRet)
this.abAxis[nDir] = false;
return bRet;
}
//---------------------------------------------------------------
// getButton (BUTTON1..4)
//---------------------------------------------------------------
public boolean getButton (int nButton)
{
return isAvailable() && this.abButtons[nButton];
}
//---------------------------------------------------------------
// getButtonAlt (BUTTON1..4) resets the button
//---------------------------------------------------------------
public boolean getButtonAlt (int nButton)
{
boolean bRet = isAvailable() && this.abButtons[nButton];
if (bRet)
this.abButtons[nButton] = false;
return bRet;
}
//---------------------------------------------------------------
// Event: joystickAxisChanged
//---------------------------------------------------------------
public void joystickAxisChanged(Joystick pJoy)
{
if (this.pJoy != pJoy)
return;
this.abAxis[UP] = this.pJoy.getY()==-1.0;
this.abAxis[DOWN] = this.pJoy.getY()==1.0;
this.abAxis[right] = this.pJoy.get) == 1.0;
this.abAxis[left] = this.pJoy.get) == -1.0;
}
//---------------------------------------------------------------
// Event: joystickButtonChanged
//---------------------------------------------------------------
public void joystickButtonChanged(Joystick pJoy)
{
if (this.pJoy != pJoy)
return;
this.abButtons[BUTTON1] = (this.pJoy.getButtons() & Joystick.BUTTON1) != 0;
this.abButtons[BUTTON2] = (this.pJoy.getButtons() & Joystick.BUTTON2) != 0;
this.abButtons[BUTTON3] = (this.pJoy.getButtons() & Joystick.BUTTON3) != 0;
this.abButtons[BUTTON4] = (this.pJoy.getButtons() & Joystick.BUTTON4) != 0;
}
}
Luego deben agregar el Joystick.jar que hace la interface con el joystick USB
También deben agregar jjstick.dll en system32 (Se puede para linux pero solo posteare para windows, lo unico que cambia es que se agregan archivos .so o .lib me parece no recuerdo).
DESCARGAR (aca estan los archivos que les nombré)
Y listo, luego crear una instancia de la clase mostrada primeramente y mostrar lo que uno desea, eventos de botones o flechas.
Espero les sirva, Saludos

