Пример #1
0
  static void pollDevices() {
    // Poll the input devices while we're here
    if (Mouse.isCreated()) {
      Mouse.poll();
      Mouse.updateCursor();
    }

    if (Keyboard.isCreated()) {
      Keyboard.poll();
    }

    if (Controllers.isCreated()) {
      Controllers.poll();
    }
  }
Пример #2
0
  public static void main(String[] argv) {

    // Create the environment of controllers
    try {
      Controllers.create();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
    }

    // Print how many controllers there are
    int count = Controllers.getControllerCount();
    System.out.println(count + " Controllers Found");

    // Print the name of each controller
    for (int i = 0; i < count; i++) {
      Controller controller = Controllers.getController(i);
      System.out.println(controller.getName() + " ");
      System.out.println("Number of Rumblers " + controller.getRumblerCount());
      System.out.println("Index Number " + controller.getIndex());
    }

    // If there are no controllers, exit program
    if (count == 0) {
      System.exit(0);
    }

    TestControllers[] controllerWindows = new TestControllers[count];
    for (int i = 0; i < count; i++) {
      controllerWindows[i] = new TestControllers(i);
    }

    // Start the "Game"
    boolean running = true;
    while (running) {
      // Sleep for 100 milliseonds, no need to poll too fast
      try {
        Thread.sleep(100);
      } catch (Exception e) {
      }
      ;

      // Poll all the controllers
      Controllers.poll();

      /*
       * Controllers have an event listener
       * Whenever a button is pushed it add the event
       * it to the buffer of the controller instance
       * As long as the buffer has something in it
       * we print it out                                 *
       */
      while (Controllers.next()) {
        //	                                System.out.println("Event Fired: ");
        //
        // System.out.println("\t"+Controllers.getEventNanoseconds());
        //
        // System.out.println("\t"+Controllers.getEventSource()+":"+Controllers.getEventControlIndex()+":"+Controllers.isEventButton());
        //
        // System.out.println("\t"+Controllers.isEventXAxis()+":"+Controllers.isEventYAxis());

        // Controller number
        int controllerNumber = Controllers.getEventSource().getIndex();
        // Button number
        int buttonNumber = Controllers.getEventControlIndex();
        /*
         * Pressing a button on an xBox controller slightly alters the analog values
         * This causes multiple unwanted events on button push
         * By checking to see if the event was a button we can strip out the uneeded events
         */
        if (Controllers.isEventButton() == true) {
          handleButtonPush(controllerNumber, buttonNumber);
        }
      }

      for (int i = 0; i < count; i++) {
        controllerWindows[i].updateDetails();
      }
    }
  } // end main