Jump to content

[SOLVED] redefine mouse button


photo

Recommended Posts

Dear Team,

 

I want to detect the click action(not press) for the right mouse button in the control.h, as I know the engine.app.getMouseButtonState(APP_BUTTON_RIGHT) can only return the state of Pressed case, but cannot for the Clicked case, so how to do for the right mouse button Clicked case?

 

Best regards,

Jianghua Wei

Link to comment

Hi,

 

You can use this simple code in update() to detect mouse right button clicks:

if(engine.app.getMouseButtonState(APP_BUTTON_RIGHT) && state == 0) {
   state = 1; 
   log.message("clicked_state\n");
}
 if(engine.app.getMouseButtonState(APP_BUTTON_RIGHT)) {
   state = 2; 
   //log.message("pressed_state\n");
}
 if(!engine.app.getMouseButtonState(APP_BUTTON_RIGHT)) {
   state = 0; 
   //log.message("released_state\n");
}

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Hi,

 

You can use this simple code in update() to detect mouse right button clicks:

if(engine.app.getMouseButtonState(APP_BUTTON_RIGHT) && state == 0) {
   state = 1; 
   log.message("clicked_state\n");
}
 if(engine.app.getMouseButtonState(APP_BUTTON_RIGHT)) {
   state = 2; 
   //log.message("pressed_state\n");
}
 if(!engine.app.getMouseButtonState(APP_BUTTON_RIGHT)) {
   state = 0; 
   //log.message("released_state\n");
}
Thanks!

 

 

Dear Sir , thank you for your supporting, but I have trouble when using this in the code( I'm really a new guy)

here is the code and I want to detect the combination of middel mouse button pressed and right mouse button clicked.

Could you please show me how to modify it and achieve  my goal? Thank you very much!

 

if(engine.controls.isMouseEnabled() && getGuiActivity() == 0) {

            int button = gui.getMouseButton();

            float dx = engine.controls.getMouseDX();

            float dy = engine.controls.getMouseDY();

 

            if(button & APP_BUTTON_LEFT) {

                phi += dx;

                theta += dy;

            }

            //Here I want to detect the middle mouse button pressed and the right mouse button clicked

            if(button & APP_BUTTON_MIDDLE) {

                if(engine.app.getMouseButtonState(APP_BUTTON_RIGHT) && mouse_status == 0) {

                

                   distance -= toolsGetCameraMaxVelocity() * dy / 20.0f;

                    distance = max(distance,toolsGetCameraZNear() * 2.0f);

                }

                else position -= (x * dx - y * dy) * toolsGetCameraMaxVelocity() / 20.0f;

            }

            

        }

Link to comment

I have solved it with another method by defining a variable i and detect the state like yours but not the same way. Seems a bit complex but really work.
anyway, thank you very much!! If you have better solution, I will be happy to change it to yours!
 
int i;
 
if(button & APP_BUTTON_MIDDLE) {
                if(engine.app.getMouseButtonState(APP_BUTTON_RIGHT) ) {
                i=1;         
                    }
                 if(i==1) { distance += toolsGetCameraMaxVelocity() * dy / 20.0f;
                    distance = max(distance,toolsGetCameraZNear() * 2.0f);
                }
                else position -= (x * dx - y * dy) * toolsGetCameraMaxVelocity() / 20.0f;
            }
            if(!engine.app.getMouseButtonState(APP_BUTTON_MIDDLE)) {
            i=0;
            }
}

Link to comment
  • 3 weeks later...

Hi,

 

You can use this simple code in update() to detect mouse right button clicks:

if(engine.app.getMouseButtonState(APP_BUTTON_RIGHT) && state == 0) {
   state = 1; 
   log.message("clicked_state\n");
}
 if(engine.app.getMouseButtonState(APP_BUTTON_RIGHT)) {
   state = 2; 
   //log.message("pressed_state\n");
}
 if(!engine.app.getMouseButtonState(APP_BUTTON_RIGHT)) {
   state = 0; 
   //log.message("released_state\n");
}

Thanks!

 

 

Dear sir ,

 

I tried to use your code in a function, but it seems not work

 

if I use your code derectly, error say the state is not defined with the value.

 

so I try to modify to this, failed again.

 

Could you help me on this?

 

 

int mouseevents(string button){

        

        if(!engine.app.getMouseButtonState(button)) {

           state = 0;

           //log.message("released_state\n");

        }

        if(engine.app.getMouseButtonState(button) && state == 0) {

           state = 1;

           //log.message("clicked_state\n");

        }

        if(engine.app.getMouseButtonState(button)) {

             state = 2;

             //log.message("pressed_state\n");

        }

        if (state ==1) return 1;

    }

Link to comment

Dear silent,

 

it works now ,I define the wrong initial state value.

Thank you very much!

 

best regards,

 

 

B

 

Hello, Joshua!

 

Please, check the attached test world.

 

 

attachicon.giftest.zip

BTW, it seem even I press the mouse button, the first statu is clicked,and then are pressed.

 

so is there a better method to identify the clicked and pressed?

Link to comment

If you want to detect pressed callback before clicked you can use following code:

int state = 0;

int update() {
	if(engine.app.getMouseButtonState(APP_BUTTON_RIGHT) && state == 0) {
		state = 1; 
		log.message("pressed_state\n");
	}
	if(!engine.app.getMouseButtonState(APP_BUTTON_RIGHT) && state == 1) {
		state = 0;
		log.message("clicked_state\n");
	}

	return 1;
}

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
×
×
  • Create New...