Skip to content

Instantly share code, notes, and snippets.

@esmitt
Last active April 26, 2021 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esmitt/7ca96193f2c320ba438e0453f9136c20 to your computer and use it in GitHub Desktop.
Save esmitt/7ca96193f2c320ba438e0453f9136c20 to your computer and use it in GitHub Desktop.
VTK way using lambda function in C++ to detect when a key was pressed
vtkNew<vtkCallbackCommand> keypressCallback;
auto KeypressCallbackFunction = [](vtkObject* caller, long unsigned int vtkNotUsed(eventId), void* clientData, void* vtkNotUsed(callData)) {
vtkRenderWindowInteractor* iren = static_cast<vtkRenderWindowInteractor*>(caller);
std::cout << "Pressed: " << iren->GetKeySym() << std::endl;
};
keypressCallback->SetCallback(KeypressCallbackFunction);
renderWindowInteractor->AddObserver(vtkCommand::KeyPressEvent, keypressCallback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment