jianghua.wei Posted September 9, 2014 Share Posted September 9, 2014 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
silent Posted September 10, 2014 Share Posted September 10, 2014 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: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
jianghua.wei Posted September 15, 2014 Author Share Posted September 15, 2014 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
jianghua.wei Posted September 15, 2014 Author Share Posted September 15, 2014 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
jianghua.wei Posted September 30, 2014 Author Share Posted September 30, 2014 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
silent Posted September 30, 2014 Share Posted September 30, 2014 Hello, Joshua! Please, check the attached test world. test.zip How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
jianghua.wei Posted September 30, 2014 Author Share Posted September 30, 2014 Hello, Joshua! Please, check the attached test world. test.zip Dear silent, it works now ,I define the wrong initial state value. Thank you very much! best regards, Link to comment
jianghua.wei Posted September 30, 2014 Author Share Posted September 30, 2014 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. test.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
silent Posted September 30, 2014 Share Posted September 30, 2014 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: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Recommended Posts