Well, first of all I'd like to make a suggestion to have an "Input Support" section to deal with mouse, keyboard, and joystick input for jME, but since there isn't one now this question will have to fit in general.
I don't believe there's currently a way to do this, but just to make sure I thought I'd check. Is there a way to get a button press event from any device? Like in Battlefield 2 (for those of you awesome enough to play it) when you are setting up key bindings it just pops up a request for you to press the button you want assigned to that binding. I would like to implement something like that in my games for key assignments. So if someone wants to assign a key on their keyboard, a button on the joystick, a button on the mouse, an axis on the joystick, or an axis on the mouse then I can just say, "what was pressed?" and presto I have the event. Any way to do that without cycling through mouse, keyboard, and joystick support looking for an event?
If not, is there a desire for this support from others? I will write the support if it's not in place and just need to know whether it should go into jME or in my own proprietary code. :o
I was looking at JInput and realized that it can support keyboard, mouse, and joystick. We're only using the joystick support, right? Any thoughts on making the switch to JInput for keyboard and mouse as well?
I created a old input system to use with JOGL, I my of used Jinput for the keyboard and mouse. LWJGL's input worked better back then but that was 2 years ago.
Elias as friends have done a lot of work on jinput since then. We even have a properly working osx version now too
Endolf
darkfrog said:
Is there a way to get a button press event from any device?
No, but you can simply subscribe a single listener for all devices by registering it for each device. So it's not really a problem that you cannot specify ALL_DEVICES, is it?
Perhaps not…I've been looking a bit at JInput and I really like it. I'm considering using it directly instead of the jME input system. It seems relatively straight-forward and extremely powerful. Is there anything that the jME input supports that JInput would not?
Jinput has no concept of a pointer, only a mouse. A mouse is a relative device, a pointer has a coord system. This means that you can't tell where the mouse is, only how much it has moved. Of course, you can create a pointer (ie, image on a quad moving around the screen) anywhere you want, and use that as your start point if you want a pointer on the screen inside your jme application.
Anything else JME does is capable of being done over the top of jinput.
HTH
Endolf
darkfrog said:
Perhaps not....I've been looking a bit at JInput and I really like it. I'm considering using it directly instead of the jME input system. It seems relatively straight-forward and extremely powerful. Is there anything that the jME input supports that JInput would not?
Of course not - the jME Input system abstracts from jInput and lwjgl input. But this abstraction is absolutely needed, I think. E.g. it allows you to do exactly what you asked for above: handle different devices (Mouse, Joystick, Keyboard, Virtual Devices like Screen-Buttons etc.) with the same interfaces. Additionally it allows you to exchange input handling for single devices (like Mouse with lwjgl, Joystick with jinput).
I don't think there's a need to revamp the input system again (of course, as I have done so lately ;))
Good points. I'll look at this more in-depth tonight and then probably post more.
Endolf, it would seem that JInput is not thread-safe.
It's like the whole OpenGL world wants to run in a single thread.
I've looked at JInput some more and I really do like it, I just wish there were event listeners like the ControllerListeners. It would be great if I could simply have:
controller.addListener(myEventListener);
Instead of having to go through each controller and each component to find out the current status.
I RECANT! :oops:
Okay, Irrisor, my good friend, you were correct. I shall sing the praises of jME's input system henceforth.
I went back to look at the input handling in jME and had previously never used the KeyboardInputHandler, MouseInputHandler, and JoystickInputHandler…that's exactly what I wanted.
I do have one issue. I'm a little confused why the JoystickInput defaults to DummyJoystickInput instead LWJGLJoystickInput? I have to explicitly set the provider in order to use the LWJGLJoystickInput. Since everything else defaults to LWJGL it seems pretty strange that Joystick doesn't.
One more comment.
I've been noticing the joystick events don't "catch". I can use it just fine for a bit and then all of a sudden it doesn't register a move of the joystick. Have you seen this before? I know it's not my joystick because otherwise I'd die a lot more at Battlefield 2. :P I'm using event listeners (which I haven't tried switching out for direct event checking yet to see if that makes any difference) and other than that they're working great.
Well no joystick is the default because many apps don't use joysticks. And some people had issues with the joystick support (there still is one ArrayOutOfBoundsException, which can be fixed by a new jinput version, see some other thread here).
I'm not sure what you mean with "catch", but it is possible that some joystick events are missed if you e.g. press a button multiple times a frame. The current implementation does not queue them (that could be changed, they are queued for mouse buttons and keyboard).
I'll do some more digging tonight, but it seems as though sometimes events get missed. Like I'll move my joystick and it will turn, then I move it back to turn the other way and it doesn't turn…if I let go of the joystick and move it again it will turn. It could be part of my code. I sort of hacked it together hardcoding a lot of aspects. My next goal is to make an extensible key binding system in Swing that mimicks the style of games like Battlefield 2. Depending on how it works out depends if I'll try to contribute this back to the community.
Thanks irrisor