159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage jme3test.input; 259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.app.SimpleApplication; 459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.JoyInput; 559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.Joystick; 659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.controls.AnalogListener; 759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.controls.JoyAxisTrigger; 859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.system.AppSettings; 959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class TestJoystick extends SimpleApplication implements AnalogListener { 1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public static void main(String[] args){ 1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta TestJoystick app = new TestJoystick(); 1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta AppSettings settings = new AppSettings(true); 1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta settings.setUseJoysticks(true); 1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta app.setSettings(settings); 1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta app.start(); 1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Override 2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void simpleInitApp() { 2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Joystick[] joysticks = inputManager.getJoysticks(); 2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (joysticks == null) 2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta throw new IllegalStateException("Cannot find any joysticks!"); 2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta for (Joystick joy : joysticks){ 2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta System.out.println(joy.toString()); 2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addMapping("DPAD Left", new JoyAxisTrigger(0, JoyInput.AXIS_POV_X, true)); 3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addMapping("DPAD Right", new JoyAxisTrigger(0, JoyInput.AXIS_POV_X, false)); 3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addMapping("DPAD Down", new JoyAxisTrigger(0, JoyInput.AXIS_POV_Y, true)); 3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addMapping("DPAD Up", new JoyAxisTrigger(0, JoyInput.AXIS_POV_Y, false)); 3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addListener(this, "DPAD Left", "DPAD Right", "DPAD Down", "DPAD Up"); 3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addMapping("Joy Left", new JoyAxisTrigger(0, 0, true)); 3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addMapping("Joy Right", new JoyAxisTrigger(0, 0, false)); 3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addMapping("Joy Down", new JoyAxisTrigger(0, 1, true)); 3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addMapping("Joy Up", new JoyAxisTrigger(0, 1, false)); 4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta inputManager.addListener(this, "Joy Left", "Joy Right", "Joy Down", "Joy Up"); 4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void onAnalog(String name, float isPressed, float tpf) { 4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta System.out.println(name + " = " + isPressed); 4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void onAction(String name, boolean isPressed, float tpf) { 4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta System.out.println(name + " = " + isPressed); 4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta} 52