[SOLVED] How to use RawInputListener

Hi all,

I’ve read through the javadoc and similar topics but I’m still confused how to use it properly.

I’m trying to get it so that when the user presses any key / gamepad button or clicks the mouse etc… that input is outputted to the console, without having to setup listeners and mappings.

Mainly what I’m trying to figure out is would it make more sense to setup mappings / listeners for ALL inputs, or to setup ONE thing (RawInputListener) that can listen for all inputs?


  • Snoogie

What’s the actual question? What have you tried?

Really, it’s as simple as… make a class that implements RawInputListener and then register it with the InputManager.

For way better more advanced input mapping, you can also look at Lemur’s InputMapper which wraps InputManager and provides a bunch of nice stuff like easy scaling, remapping, combo-keys, etc… It can be used without using the rest of Lemur.

…though some other parts of Lemur are useful on their own also:

For input mapper examples:

I’ve tried what you said but I guess I’m not doing it properly. Here’s my code :

public class MyRawInputListener implements RawInputListener 
    public void onKeyEvent(KeyInputEvent evt) 

In the other class I have :

MyRawInputListener myRawInputListener = new MyRawInputListener();

It gives me “Not supported yet.” and I’m not sure why. Any ideas?

It gives you “Not supported yet” because you throw the exception right there.

Am I on TV?

Sorry I fixed my post because I had removed that line but you’re right. It was the throw from the onMouseMotionEvent function that was throwing me off. I couldn’t figure out why it was failing immediately before I even pressed a key

Thanks for fixing my dumb mistake!

@pspeed me again I know :slight_smile:
Lemur does have different naming for the game controller buttons, like nicer ones than just button numbers. Does Lemur have a possibility to translate button 5 to JOYSTICK_RIGHT1 and so on? Thanks.

EDIT: The answer is probably “no”, the InputMapper of Lemur does not expose the button mapping. So I have to copy that mapping in to my code in that case.

I can read this question in a few different ways. Can you provide context about what you are actually trying to do?

Yes sure. I’m still on this customize your controller buttons on the Lemur FunctionId. For that I have a JSON file where I have my default mappings and write one for custom mappings. That file looks like this

        jump: JOYSTICK_BUTTON1
        shoot: JOYSTICK_BUTTON3
        switchWeapon: JOYSTICK_RIGHT1, JOYSTICK_RIGHT2
        reload: JOYSTICK_BUTTON4

        moveX: JOYSTICK_LEFT_X
        moveNegY: JOYSTICK_LEFT_Y

Now I wanted to select the action i.e. “Jump” in my “customize gamepad” menu and then listen with the raw input handler which button the player is gone press. Then I know ok it is button 1 or 2 or 3 or 9 or what ever but not JOYSTICK_RIGHT1 or JOYSTICK_BUTTON4. So I wanted a mapping for this.

Or is there an easier way that I didn’t think of? For the keyboard it was kind of straight forward had to find e class field with that number. But here?

EDIT: It’s not pressing as currently I do it with another group of Lemur FunctionId for all buttons for regular gamepads (A,B,X,Y,RB,RT, LB, LT) which I can listen to, it works, just thought maybe with the raw input handler I could address more buttons than just the “regular” set.