[vtkusers] Handling "holding down" a key

David Gobbi david.gobbi at gmail.com
Sun Sep 12 10:35:57 EDT 2010


Hi David,

The "key repeat" is done by the operating system, not by VTK.  The
only keys that do not repeat are the modifier keys: shift, control,
alt, etcetera.  What key are you using, and on what operating system
or GUI toolkit?

The work-around is to add a timer to your code, so that if a repeat
occurs within a certain number of milliseconds you can ignore it.

  David


On Sun, Sep 12, 2010 at 7:55 AM, David Doria <daviddoria+vtk at gmail.com> wrote:
> 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
> _______________________________________________
> 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