Home | History | Annotate | Download | only in input
      1 package jme3test.input;
      2 
      3 import com.jme3.app.SimpleApplication;
      4 import com.jme3.input.JoyInput;
      5 import com.jme3.input.Joystick;
      6 import com.jme3.input.controls.AnalogListener;
      7 import com.jme3.input.controls.JoyAxisTrigger;
      8 import com.jme3.system.AppSettings;
      9 
     10 public class TestJoystick extends SimpleApplication implements AnalogListener {
     11 
     12     public static void main(String[] args){
     13         TestJoystick app = new TestJoystick();
     14         AppSettings settings = new AppSettings(true);
     15         settings.setUseJoysticks(true);
     16         app.setSettings(settings);
     17         app.start();
     18     }
     19 
     20     @Override
     21     public void simpleInitApp() {
     22         Joystick[] joysticks = inputManager.getJoysticks();
     23         if (joysticks == null)
     24             throw new IllegalStateException("Cannot find any joysticks!");
     25 
     26         for (Joystick joy : joysticks){
     27             System.out.println(joy.toString());
     28         }
     29 
     30         inputManager.addMapping("DPAD Left", new JoyAxisTrigger(0, JoyInput.AXIS_POV_X, true));
     31         inputManager.addMapping("DPAD Right", new JoyAxisTrigger(0, JoyInput.AXIS_POV_X, false));
     32         inputManager.addMapping("DPAD Down", new JoyAxisTrigger(0, JoyInput.AXIS_POV_Y, true));
     33         inputManager.addMapping("DPAD Up", new JoyAxisTrigger(0, JoyInput.AXIS_POV_Y, false));
     34         inputManager.addListener(this, "DPAD Left", "DPAD Right", "DPAD Down", "DPAD Up");
     35 
     36         inputManager.addMapping("Joy Left", new JoyAxisTrigger(0, 0, true));
     37         inputManager.addMapping("Joy Right", new JoyAxisTrigger(0, 0, false));
     38         inputManager.addMapping("Joy Down", new JoyAxisTrigger(0, 1, true));
     39         inputManager.addMapping("Joy Up", new JoyAxisTrigger(0, 1, false));
     40         inputManager.addListener(this, "Joy Left", "Joy Right", "Joy Down", "Joy Up");
     41     }
     42 
     43     public void onAnalog(String name, float isPressed, float tpf) {
     44         System.out.println(name + " = " + isPressed);
     45     }
     46 
     47     public void onAction(String name, boolean isPressed, float tpf) {
     48         System.out.println(name + " = " + isPressed);
     49     }
     50 
     51 }
     52