[vtkusers] Handling "holding down" a key

David Doria daviddoria+vtk at gmail.com
Sun Sep 12 09:55:23 EDT 2010


I want to change the functionality of an interactor style based on if
a key is being held down while performing the interaction. I noticed
that when I hold down a key, the OnKeyDown() and OnKeyUp() functions
of vtkInteractorStyle are called over and over while the key is being
held, rather than only once when the key is pressed down and once when
the key is released.

class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{
....
    virtual void OnKeyDown()
    {
      std::cout << "KeyDown" << std::endl;
      vtkInteractorStyleTrackballCamera::OnKeyDown();
    }
    virtual void OnKeyUp()
    {
      std::cout << "KeyUp" << std::endl;
      vtkInteractorStyleTrackballCamera::OnKeyUp();
    }

That is, holding the key down only once produces

KeyDown
KeyUp
KeyDown
KeyUp
KeyDown
KeyUp
.... (repeat indefinitely while the key is held)

What I want to be able to do is set a flag when the key is first
pressed down, then un-set the flag when the key is released. Due to
the above, the flag would constantly toggle while the key is being
press, which is definitely not appropriate.

Anyone know how to do this?

Thanks,

David



More information about the vtkusers mailing list