[vtkusers] Re: KeyPressEvent Tcl

Goodwin Lawlor goodwin.lawlor at ucd.ie
Wed Nov 15 10:00:39 EST 2006


Robert V Canning wrote:
> Hi,
> 
>       I am trying to capture when a user presses the arrow keys.  I  am
> using the KeyPressEvent observer to trap for key strokes but I am unable to
> find out how to test for the arrow keys in Tcl.   Is there anything like a
> constant I can use?
> 
>       if {$keypressed == LeftArrow){
>             dosomething {}
>       }
> 
> I am using VTK 5.0.2 with Tcl 8.4.13 on a Windows XP system.

Hi Bob,

Do you mean something like:



package require vtk
package require vtkinteraction
wm withdraw .

vtkCubeSource cube

vtkPolyDataMapper mapper
   mapper SetInputConnection [cube GetOutputPort]

vtkActor actor
   actor SetMapper mapper

vtkCamera cam

vtkRenderer ren
   ren AddActor actor
   ren SetActiveCamera cam
   ren ResetCamera

vtkRenderWindow renwin
   renwin AddRenderer ren

vtkRenderWindowInteractor iren
   iren SetRenderWindow renwin
   iren AddObserver UserEvent {wm deiconify .vtkInteract}
   iren AddObserver KeyPressEvent cbKeyPress
   iren Initialize

   proc cbKeyPress {} {

     switch [iren GetKeySym] {
       Down {cam Elevation -3; UpdateRender}
       Up {cam Elevation 3; UpdateRender}
       Left {cam Azimuth -3; UpdateRender}
       Right {cam Azimuth 3; UpdateRender}
       default {}
     }
   }

   proc UpdateRender {} {
     cam OrthogonalizeViewUp
     renwin Render
   }




More information about the vtkusers mailing list