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. :)
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.
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.
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();
}
}