I am using VTK in C++ for the project with the interactor style vtkInteractorStyleTrackballCamera. Thereafter, I am trying to override the functionalities to create a custom interaction style. Herein is my code for custom interaction style.
class customMouseInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static customMouseInteractorStyle* New();
vtkTypeMacro(customMouseInteractorStyle, vtkInteractorStyleTrackballCamera);
virtual void OnLeftButtonDown() override
{
std::cout << "Pressed left mouse button." << std::endl;
}
virtual void OnMiddleButtonDown() override
{
std::cout << "Pressed middle mouse button." << std::endl;
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
vtkRenderWindowInteractor* rwi = this->Interactor;
std::string key = rwi->GetKeySym();
std::cout << "KEYY: " << key << "\n";
if(key == "Ctrl") {
std::cout << "panning started" << std::endl;
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
vtkInteractorStyleTrackballCamera:: OnMiddleButtonDown();
std::cout << "panning stopped" << std::endl;
}
}
virtual void OnMiddleButtonUp() override
{
std::cout << "Left the middle mouse button." << std::endl;
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
vtkInteractorStyleTrackballCamera:: OnMiddleButtonUp();
}
virtual void OnRightButtonDown() override
{
std::cout << "Pressed right mouse button." << std::endl;
}
};
vtkStandardNewMacro(customMouseInteractorStyle);
The problem I seem to be facing pertains to the function onMiddleButtonDown(). Herein, when I try getting the key that’s pressed using vtkRenderWindowInteractor* rwi = this->Interactor; std::string key = rwi->GetKeySym(); , I always seem to be getting a blank string, this is what I receive on cout:
I was wondering if I am doing anything wrong when it comes to using the functionalities? And how do I get the expected behavior in such a scenario?
This is the example I followed to get the key that’s pressed: examples.vtk.org/site/Cxx/Interaction/KeypressEvents/.