|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Know a good Java library to read from a Gamepad or Joystick?
I'm working on a program for our AUV (Not for FRC) and I need to be able to get values from a gamepad/joystick in a java program.
So far we've tried LWJGL and JInput, and both have issues with detecting if a controller disconnected (they will print an error to command line, but not actually throw an error). It would also be nice (but not necessary) if the library was packed up into a .jar, so that we wouldn't need to install .dll's for each computer the program would run on. Thanks in advance for all replies. |
|
#2
|
||||
|
||||
|
Re: Know a good Java library to read from a Gamepad or Joystick?
In JInput, the comment for net.java.games.input.Controller.poll() says:
Code:
/** * Polls axes for data. Returns false if the controller is no longer valid. Code:
bool present = org.lwjgl.glfw.GLFW.glfwJoystickPresent(GLFW_JOYSTICK_1) == org.lwjgl.opengl.GL11.GL_TRUE; |
|
#3
|
|||
|
|||
|
Re: Know a good Java library to read from a Gamepad or Joystick?
Yeah. I would just poll the controller with JInput and if you need an exception thrown, do it upon receiving 'false'
|
|
#4
|
|||
|
|||
|
Re: Know a good Java library to read from a Gamepad or Joystick?
I'm pretty sure LWJGL uses jinput behind the scenes for input handling (at least it used to), so you will likely get the same behavior with both libraries.
I wrote an application a while back that used some really hacky code to re-initialize Jinput to rescan for joysticks, which might be somewhat helpful. IIRC, the controller listener hooks worked correctly on Windows, but that hack was necessary on Linux. It's been a while, so I forget how I dealt with the native libraries, but that application might also be able to help with that. |
|
#5
|
||||
|
||||
|
Re: Know a good Java library to read from a Gamepad or Joystick?
Here's one I started using. I really like it so far and does everything that you require.
https://github.com/gary-rowe/hid4java -Andres |
|
#6
|
||||
|
||||
|
Re: Know a good Java library to read from a Gamepad or Joystick?
Quote:
Weird. I tried that in LWJGL, but it didn't work. I assumed it wouldn't work in JInput, but looks like it does. LWJGL's docs How would you check if the controller has reconnected? Would the .poll work again? What if you connected a new joystick? How would you rebuild the list attached gamepads, if, say, you started the program and then connected a controller? IIRC, both JInput and LWJGL only build the list the first time you call it, and will give you only that list from that point on. Last edited by Maxwell777 : 18-09-2015 at 14:20. Reason: forgot stuff |
|
#7
|
||||
|
||||
|
Re: Know a good Java library to read from a Gamepad or Joystick?
Quote:
Quote:
Quote:
I assume if JInput is able to fire events on controller state changes that it's also maintaining an updated list, but I haven't verified this. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|