[vtkusers] Catching arrow keys in linux

David Gobbi david.gobbi at gmail.com
Fri Jan 22 15:47:51 EST 2010


It's failing because you are doing this:

  rwi->GetKeySym() == "Up"

Throw in a strcmp or something.

 - David


On Fri, Jan 22, 2010 at 1:36 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
> 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>
>> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list