Problem with GameControl and MouseButtonBinding

i want to use GameControl and MousebuttonBinding to detect if the left or right MouseButton has been pressed.



        GameControl fireWeapon = manager.addControl("Fire Weapon");
        fireWeapon.addBinding(new MouseButtonBinding(java.awt.event.MouseEvent.BUTTON1));
        Runnable fire = new Runnable() {
            public void run() {
                System.out.println("Fire!!");
            }
        };
        ActionRepeatController fireWeaponController = new ActionRepeatController(fireWeapon, fireRate, fire);
        this.addController(fireWeaponController);



I use the awt MouseEvent to declare the Button1, in awt the MouseButtons are defined as follows:


    public static final int NOBUTTON = 0;
    public static final int BUTTON1 = 1;
    public static final int BUTTON2 = 2;



Now if i press the left mouse button nothing happens, but the action is executed if i press the right button..

It seems jme thinks 0 is the LMB, 1 the RMB.
I guess i just used the wrong Class to define the button number, but i can't figure out how to do that correctly.

Whats is the correct way do define the button number? 

I don't remember off the top of my head, but I believe it's one of the jME objects' (like Mouse) that define it.  It's possible it's LWJGL, but I don't believe so.

i looked again through all the Mouse and Input Classes but there is no such thing.



The LWJGL Mouse just starts counting with 0 and keeps a name with a number in a hashmap, like {"MOUSE0",0}.



http://java-game-lib.svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java?view=markup


private static void initialize() {
    Sys.initialize();
 
    // Assign names to all the buttons
    buttonName = new String[16];
    for (int i = 0; i < 16; i++) {
       buttonName[i] = "BUTTON" + i;
       buttonMap.put(buttonName[i], new Integer(i));
    }
    initialized = true;
}



i guess is just use 0 and 1.
its just a bit confusing that lwjgl starts with 0 and awt with 1.

Okay, just got home and looked in the source.  There was nothing previously set to support this.  I went ahead and added MouseButtonBinding.LEFT_BUTTON, RIGHT_BUTTON, and MIDDLE_BUTTON that you can use when defining the binding.



Will that work for you? :wink:

perfect thanks

:smiley: