<div dir="ltr">Hi David,<div><br></div><div>Great. It works. Thanks for the help.</div><div><br></div><div>BTW,</div><div>Here is the detail. I add another observer using render window interactor.</div><div><br></div><div>renderWindowInteractor->AddObserver(vtkCommand::KeyPressEvent, seedCallback);<br></div><div><br></div><div>Then add if-else block in the callback:</div><div><pre style="white-space:pre-wrap;color:rgb(80,0,80);padding:0px;border:0px none white;margin-top:0px;margin-bottom:0px;vertical-align:top;background-image:none"><font color="#0000FF"><span style="font-size:10px;line-height:12.4799995422363px">if (event == vtkCommand::KeyPressEvent)
{
std::cout<<"key press"<<std::endl;
}</span></font></pre></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 17, 2014 at 5:17 AM, David Cole <span dir="ltr"><<a href="mailto:DLRdave@aol.com" target="_blank">DLRdave@aol.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">A "git grep" of the current git 'master' branch shows that only<br>
interactors and interactor styles actually invoke the KeyPress event:<br>
<br>
$ git grep -E "Invoke.*KeyPressEvent"<br>
GUISupport/Qt/QVTKInteractorAdapter.cxx:<br>
iren->InvokeEvent(vtkCommand::KeyPressEvent, e2);<br>
Interaction/Style/vtkInteractorStyleUser.cxx:<br>
this->InvokeEvent(vtkCommand::KeyPressEvent, NULL);<br>
Rendering/Core/vtkInteractorStyle.cxx:<br>
self->InvokeEvent(vtkCommand::KeyPressEvent,NULL);<br>
Rendering/Core/vtkRenderWindowInteractor.cxx:<br>
this->InvokeEvent(vtkCommand::KeyPressEvent, NULL);<br>
Rendering/OpenGL/vtkCarbonRenderWindowInteractor.cxx:<br>
me->InvokeEvent(vtkCommand::KeyPressEvent, NULL);<br>
Rendering/OpenGL/vtkCarbonRenderWindowInteractor.cxx:<br>
me->InvokeEvent(vtkCommand::KeyPressEvent, NULL);<br>
Rendering/OpenGL/vtkCarbonRenderWindowInteractor.cxx:<br>
me->InvokeEvent(vtkCommand::KeyPressEvent, NULL);<br>
Rendering/OpenGL/vtkWin32RenderWindowInteractor.cxx:<br>
this->InvokeEvent(vtkCommand::KeyPressEvent, NULL);<br>
Rendering/OpenGL/vtkXRenderWindowInteractor.cxx:<br>
me->InvokeEvent(vtkCommand::KeyPressEvent, NULL);<br>
Rendering/OpenGL2/vtkAndroidRenderWindowInteractor.cxx:<br>
this->InvokeEvent(vtkCommand::KeyPressEvent, NULL);<br>
Rendering/OpenGL2/vtkWin32OpenGLRenderWindowInteractor.cxx:<br>
this->InvokeEvent(vtkCommand::KeyPressEvent, NULL);<br>
Rendering/OpenGL2/vtkXOpenGLRenderWindowInteractor.cxx:<br>
me->InvokeEvent(vtkCommand::KeyPressEvent, NULL);<br>
<br>
You will have to call AddObserver on the render window interactor, or<br>
the current interactor style in order to receive the KeyPress event.<br>
<br>
<br>
HTH,<br>
David C.<br>
<div><div class="h5"><br>
<br>
<br>
On Tue, Dec 16, 2014 at 8:09 PM, Erkang Cheng <<a href="mailto:ekyaya@gmail.com">ekyaya@gmail.com</a>> wrote:<br>
> Hi all,<br>
><br>
> I am playing with the vtkSeedWidget example, which is available from:<br>
> <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/SeedWidget" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/SeedWidget</a><br>
><br>
> I am stuck at how to add kepress event.<br>
><br>
> I tried to add<br>
> seedWidget->AddObserver(vtkCommand::KeyPressEvent,seedCallback);<br>
><br>
> right after the following lines:<br>
> seedWidget->AddObserver(vtkCommand::PlacePointEvent,seedCallback);<br>
> seedWidget->AddObserver(vtkCommand::InteractionEvent,seedCallback);<br>
><br>
><br>
> Another change is in class vtkSeedCallback::Execute<br>
> I add one if-else blcok to capture keypress event.<br>
><br>
> virtual void Execute(vtkObject*, unsigned long event, void *calldata)<br>
> {<br>
> if (event == vtkCommand::KeyPressEvent)<br>
> {<br>
> std::cout<<"key press"<<std::endl;<br>
> }<br>
><br>
> ...<br>
><br>
> }<br>
><br>
><br>
> However, the widget can not capture keypress event.<br>
><br>
> Could anyone share the idea to add customized event in vtkSeedWidget?<br>
> Thanks.<br>
><br>
</div></div>> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at:<br>
> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/vtkusers" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
><br>
</blockquote></div></div>