[vtkusers] Catching arrow keys in linux

David Doria daviddoria+vtk at gmail.com
Fri Jan 22 15:36:08 EST 2010


On Fri, Jan 22, 2010 at 3:21 PM, David Gobbi <david.gobbi at gmail.com> wrote:

> I'm not sure what #defines you are talking about, but why not use the
> interactor "GetKeySym" method to detect arrow keys?  They have the
> names "Up", "Down", "Left", "Right".
>
>    David
>
>
> On Fri, Jan 22, 2010 at 1:18 PM, David Doria <daviddoria+vtk at gmail.com<daviddoria%2Bvtk at gmail.com>>
> wrote:
> > It seems that for win32, there are some #defines for arrow keys like
> > VK_RIGHT. I can't seem to find what should be done for non win32 - any
> > thoughts?
> >
> > Thanks,
> >
> > David
>
>
So typically I do this from inside my InteractorStyle subclass:

    virtual void OnChar()
    {
      vtkRenderWindowInteractor *rwi = this->Interactor;

      char ch = rwi->GetKeyCode() ;

      switch (ch)
      {
        case 's':
          cout << "Pressed s." << endl;
          break;
        case 'a':
          cout << "Pressed a." << endl;
          break ;
        default:
          cout << "Pressed an unhandled key: " << rwi->GetKeyCode() << endl;
          break;
      }

The problem is that OnChar() doesn't fire when the arrow keys are pressed. I
tried to use

    virtual void OnKeyDown()
    {
      vtkRenderWindowInteractor *rwi = this->Interactor;

      if(rwi->GetKeySym() == "Up")
      {
        cout << "Pressed up." << endl;
      }

      // forward events
      vtkInteractorStyleTrackballCamera::OnKeyDown();
    }

But it doesn't seem to compare to true. It also doesn't seem to flush the
buffer when I would expect?

Also, what is the difference between KeyPress and KeyDown? The documentation
is kind of broken here:
http://www.vtk.org/doc/nightly/html/classvtkInteractorStyle.html#a65fcd9765c162a6021434386037ca641

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100122/2cf23590/attachment.htm>


More information about the vtkusers mailing list