[vtkusers] Callback method to handle LeftButtonPressEvent + 'keyboard char-key pressed'

ochampao ochampao at hotmail.com
Mon Jun 18 11:22:22 EDT 2018


Hi vtkUsers,

In my code I have a callback function invoked when the
vtkCommand::LeftButtonPressEvent event is emitted. Inside the callback, I
would like to check if also a specific keyboard button is pressed. When I
try to access the button being pressed via
vtkRenderWindowInteractor::GetKeySym(), I get the following error: 

"Debug Assertion Failed! Program: ....MSVCP140D.dll, File: ...\xstring: Line
1181, Expression: invalid pointer".

How can I correctly implement this behaviour?


Here is a minimal callback method that causes the error:

// ========================
void MyLeftMousePressedCallback(
	vtkObject* caller,
	long unsigned int vtkNotUsed(eventId),
	void* vtkNotUsed(clientData),
	void* vtkNotUsed(callData))
{
	vtkRenderWindowInteractor *iren =
		static_cast<vtkRenderWindowInteractor*>(caller);

	std::string key = iren->GetKeySym();

	if ((key == "C") || (key == "c"))
		std::cout << "Do something if LeftMouseButton + C-key is pressed";
}
// ========================

and this is how the callback is registered:

// =========================
vtkNew<vtkCallbackCommand> cbk;
cbk->SetCallback(MyLeftMousePressedCallback);
renderWindowInteractor->AddObserver(
	vtkCommand::LeftButtonPressEvent, cbk);
// =========================

I have also tried extending vtkInteractorStyleImage and re-implementing the
virtual method OnLeftButtonDown(), but I get the same error when using
this->Interactor->GetKeySym(). In both cases, if GetKeySym() is replaced
with GetKeyCode(), the returned value is always '\0'. Interestingly, using
GetControlKey() works.

Thanks for your help,
Panos.







--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list