Arrow-key events in VTK on Windows
Question: Why are arrow key-press events not forwarded to the vtkRenderWindowInteractor
on Windows? Is there a workaround? Is there a general difference between
arrow-key events on Windows and Mac?

I can reproduce the problem with the following sample code. On Mac OS, I see
'Up', 'Down', 'Left' and 'Right' if I press the arrow keys. But on Windows, I
don't see anything (the callback is not entered). I wondered why this is the
case.

I use VTK 6.2.0 for python 2.7. I tested on Windows Server 2012 (similar to
Windows 8) and Windows 7 (on a virtual machine), showing both the same
behaviour.

    
    
    # -*- coding: utf-8 -*-
    import vtk
    import sys
    
    class ClickInteractorStyle(vtk.vtkInteractorStyleTrackballCamera):
        def __init__(self, parent=None):
                self.AddObserver("CharEvent",self.onKeyPressEvent)
    
        def onKeyPressEvent(self, renderer, event):        
            key = self.GetInteractor().GetKeySym()
            print key
            self.OnChar()
    
    def run():
        sphereSource = vtk.vtkSphereSource()
        sphereSource.SetCenter(0.,0.,0.)
        sphereSource.SetRadius(1.)
        sphereSource.Update()
    
        sphereMapper = vtk.vtkPolyDataMapper()
        sphereMapper.SetInputConnection(sphereSource.GetOutputPort())
    
        sphereActor = vtk.vtkActor()
        sphereActor.SetMapper(sphereMapper)
    
        renderer = vtk.vtkRenderer()
        renderWindow = vtk.vtkRenderWindow()
        renderWindow.AddRenderer(renderer)
    
        renderWindowInteractor = vtk.vtkRenderWindowInteractor()
        renderWindowInteractor.SetRenderWindow(renderWindow)
        style = ClickInteractorStyle()
        renderWindowInteractor.SetInteractorStyle(style)
        style.SetCurrentRenderer(renderer)
    
        renderer.AddActor(sphereActor)
        renderWindow.Render()
        renderWindowInteractor.Start()
    
    
    
    ###############################################################################
    # MAIN
    ###############################################################################
    if __name__ == "__main__":
        try:
            run()
        except:
            print "Unexpected error: %s", sys.exc_info()[0]
            raise
    


Answer: This fixed my problem: Replace

    
    
    self.AddObserver("CharEvent",self.onKeyPressEvent)
    

with

    
    
    self.AddObserver("KeyPressEvent",self.onKeyPressEvent)
    

