[vtkusers] How to activate KeyPress EventsinvtkXRenderWindowInteractor?

vidyadhar vidyadhar at lucidindia.net
Sun Apr 1 23:57:48 EDT 2007


Hi,
Interactor style itself is an observer on interactor. Observer added to style MAY receive the keypress event AFTER interactor style has acted on it. So I think it would be better to derive a class from suitable interactor style and override its virtual functions. Ignore the EXIT related keys and pass other keys to the base class.
HTH
Vidyadhar
  ----- Original Message ----- 
  From: Luca Pallozzi Lavorante 
  To: vtkusers at vtk.org 
  Sent: Friday, March 30, 2007 5:03 PM
  Subject: Re: [vtkusers] How to activate KeyPress EventsinvtkXRenderWindowInteractor?


  Hi Vidyadhar, thank you for you replay.
  Yesterday there has been another thread of messages dealing with the same question and, again, the Focus issue has been raised.
  I was trying to implement picking using the ´p´ key, but then I resolved using mouse events. As to the exit event caused by the `q` and `e` keys, can´t it be trapped using an observer on the Interactor?

  Thank you

       Luca


  On 3/30/07, vidyadhar <vidyadhar at lucidindia.net> wrote:
    Hi,
    I use win32 only so cannot be sure about other windowing environments. In win32, mouse events go to window under mouse cursor so render window, standalone or parented to some other window receives the mouse events. Keyboard events go to that window which has keyboard focus. This could be dialog window parent of render window or some deeper nesting (in my case nesting is very deep, using MDI window with user controls parenting render window). For this reason, keyboard events are processed in stand alone vtk window but not if it is parented. Some mechanism has to be set to pass keypress events from container upto render window interactor. This is tricky and I have not tried it beyond direct parentage case. A word of caution if you decide to try this event forwarding. Pressing 'Q', 'q', 'E' and 'e' key which are passed to interactor can cause the entire application to close down (on win32 the interactor send quit message to OS).
    HTH
    vidyadhar
      ----- Original Message ----- 
      From: Luca Pallozzi Lavorante 
      To: vtkusers at vtk.org 
      Sent: Thursday, March 29, 2007 3:43 AM
      Subject: [vtkusers] How to activate KeyPress Events invtkXRenderWindowInteractor?


      Hi everybody,
      I am trying to use a KeyPressEvent in my application using some test callback. I have followed the procedure listed below,  but when I press a key nothing happens.
      Could someone please tell me if I am missing something?
      Thank you very much for your help.

             Luca

      Code: 

      vtkXRenderWindowInteractor *iren = vtkXRenderWindowInteractor::New();

      vtkCallbackCommand *keyPressCB = vtkCallbackCommand::New();
        keyPressCB->SetClientData(iren);
        keyPressCB->SetCallback (keyPressCallback); //  keyPressCallback is created elsewhere. It prints a message.
        
      vtkInteractorStyleTrackballCamera *styleTrackball = vtkInteractorStyleTrackballCamera::New();
        styleTrackball->AddObserver(vtkCommand::KeyPressEvent, keyPressCB);

      iren->SetInteractorStyle(styleTrackball); 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070402/d8f461a9/attachment.htm>


More information about the vtkusers mailing list