LWJGL

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [FIXED] org.lwjgl.input.Controllers event buffer  (Read 4533 times)

momoka

  • Newbie
  • *
  • Offline Offline
  • Posts: 3
[FIXED] org.lwjgl.input.Controllers event buffer
« on: April 15, 2012, 02:34:12 »

I can get keyboard event key status by org.lwjgl.input.Keyboard.getEventKeyState(),
http://www.lwjgl.org/wiki/index.php?title=LWJGL_Basics_2_%28Input%29#The_Event_Buffer
but, I cannot get Joypad event button status.

org.lwjgl.input.Controllers.isEventButton() returns current org.lwjgl.input.ControllerEvent's type at Controllers event buffer(org.lwjgl.input.Controllers.events),
but no method to get event button status(pressed or released), event button number, event x axis value, and event y axis value.

I want to access Controllers's current input event.
because JInputController is updated to last status, when input events happen.

+ org.lwjgl.input.Controllers.getEventButton()
+ org.lwjgl.input.Controllers.getEventButtonStatus()
+ org.lwjgl.input.Controllers.getEventXAxisValue()
+ org.lwjgl.input.Controllers.getEventYAxisValue()


Thanks. :)
Logged

pparkkin

  • Newbie
  • *
  • Offline Offline
  • Posts: 1
Re: [RFE] org.lwjgl.input.Controllers event buffer
« Reply #1 on: May 12, 2013, 10:32:54 »

Hi.

Did you ever resolve this?

I've been trying to google all over for info on how to support controller events in LWJGL, but haven't found a solution yet.
Logged

kappa

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1226
Re: [RFE] org.lwjgl.input.Controllers event buffer
« Reply #2 on: November 01, 2013, 13:08:11 »

This is implemented in the LWJGL 2.9.1 nightly builds with the new methods being:

org.lwjgl.input.Controller.getEventButtonState()
org.lwjgl.input.Controller.getEventXAxisValue()
org.lwjgl.input.Controller.getEventYAxisValue()

Special thanks to momokan (assuming same person as momoka) for the patch via GitHub.
Logged

momoka

  • Newbie
  • *
  • Offline Offline
  • Posts: 3
Re: [FIXED] org.lwjgl.input.Controllers event buffer
« Reply #3 on: January 25, 2014, 16:43:25 »

Hi.

Thanks for merging and release!
Yes, I implemented these methods and sent as pull request.

From lwjgl ver 2.9.1, we can get all buffered (polled) controller events and its details.
About event button number, org.lwjgl.input.Controllers.getEventControlIndex() returns it.

A sample code is here.


import org.lwjgl.LWJGLException;
import org.lwjgl.input.Controllers;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class ControllerEventBufferExample {

   public void start() {
      try {
         Display.setDisplayMode(new DisplayMode(800, 600));
         Display.create();

         // prepare controllers.
         Controllers.create();
      } catch (LWJGLException e) {
         e.printStackTrace();
         System.exit(0);
      }

      // init OpenGL here
      
      while (!Display.isCloseRequested()) {
         // render OpenGL here

         pollInput();
         Display.update();
      }

      Display.destroy();
   }

   public void pollInput() {
      while (Controllers.next()) {   //   Head next event on controller event buffer.

         if (Controllers.isEventButton()) {
             //   The index of the control that cause the current event
             int         buttonIndex = Controllers.getEventControlIndex();

             //   Gets the state of the button that generated the current event
             boolean      buttonState = Controllers.getEventButtonState();

             System.out.println("Controller button event. index: " + buttonIndex + ", state: " + buttonState);
          }
          if (Controllers.isEventAxis()) {
             //   The value on a x axis of the current event
             float      xAxisValue = Controllers.getEventXAxisValue();

             //   The value on a y axis of the current event
             float      yAxisValue = Controllers.getEventYAxisValue();

             if ((xAxisValue != 0) || (yAxisValue != 0)) {
                System.out.println("Controller axis event. x: " + xAxisValue + ", y: " + yAxisValue);
             }
          }
      }
   }

   public static void main(String[] argv) {
      ControllerEventBufferExample example = new ControllerEventBufferExample();

      example.start();
    }
}
Logged