RFC: Enhance MouseLook to use any mouse button

Hi all.

The class com.jme.input.action.MouseLook allows controlling the camera with a mouse.  When a button press is required, the current implementation is hardcoded to check if the left mouse button is down.  See line 137 of the source:

(line 139)  if(!buttonPressRequired || MouseInput.get().isButtonDown(0)) {

I would like to enhance MouseLook to allow any mouse button to be used.  To maintain backward compatibility with existing behavior, the left mouse button will be the default.
The changes to MouseLook required to implement this functionality will be:

1) Adding a new private int field to hold which mouse button to check for when a button press is required, and defaulting it to the left button, which is consistent with the current behavior.

    private int mouseButton = MouseButtonBinding.LEFT_BUTTON;

2) Adding a getter and setter for this field.  The setter would normally be called with one of the MouseButtonBinding constants.

   public int getMouseButton() {
      return mouseButton;

   public void setMouseButton(final int mouseButton) {
      this.mouseButton = mouseButton;

3) Changing performAction to check for the assigned button when a button press is required by replacing

        if(!buttonPressRequired || MouseInput.get().isButtonDown(0)) {


        if(!buttonPressRequired || MouseInput.get().isButtonDown(mouseButton)) {

I made these changes locally a few months ago because in my program I wanted the right mouse button to control mouse-looking and I hope the community will agree that this enhancement should become part of jME.  I will be sure to include javadocs on the new getter and setter, as well as updating the javadocs for performAction.

I will wait a few days for feedback before committing these changes.

Thanks for sharing your opinion,

- Ray Malanga

P.S.  Here's a patch but this one doesn't include javadocs modifications yet -- I'm waiting for fedback first :)

Index: src/com/jme/input/action/MouseLook.java
--- src/com/jme/input/action/MouseLook.java   (revision 4032)
+++ src/com/jme/input/action/MouseLook.java   (working copy)
@@ -34,6 +34,7 @@
 import com.jme.input.Mouse;
 import com.jme.input.MouseInput;
+import com.jme.input.controls.binding.MouseButtonBinding;
 import com.jme.math.Vector3f;
 import com.jme.renderer.Camera;
@@ -60,6 +61,7 @@
     private InputActionEvent event;
     private boolean buttonPressRequired = false;
+    private int mouseButton = MouseButtonBinding.LEFT_BUTTON;
      * Constructor creates a new <code>MouseLook</code> object. It takes the
@@ -134,7 +136,7 @@
     public void performAction(InputActionEvent evt) {
         float time = 0.01f * speed;
-        if(!buttonPressRequired || MouseInput.get().isButtonDown(0)) {
+        if(!buttonPressRequired || MouseInput.get().isButtonDown(mouseButton)) {
             if (mouse.getLocalTranslation().x > 0) {
                 event.setTime(time * mouse.getLocalTranslation().x);
@@ -160,4 +162,13 @@
     public void setButtonPressRequired(boolean buttonPressRequired) {
         this.buttonPressRequired = buttonPressRequired;
+   public int getMouseButton() {
+      return mouseButton;
+   }
+   public void setMouseButton(final int mouseButton) {
+      this.mouseButton = mouseButton;
+   }
No newline at end of file

Too bad MouseButtonBinding is still using constant ints instead of enums 

Well, do you want to generate an enum with 65K+ entries? :P  (mouse/controller button button count is not limited)

irrisor said:

Well, do you want to generate an enum with 65K+ entries? :P  (mouse/controller button button count is not limited)

oh  :-o