# How to use generic window interactor?

**URL:** https://discourse.vtk.org/t/how-to-use-generic-window-interactor/11960
**Category:** Support
**Tags:** code
**Created:** [July 18, 2023, 1:57pm UTC](https://discourse.vtk.org/t/how-to-use-generic-window-interactor/11960 "2023-07-18T13:57:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [July 18, 2023, 1:57pm UTC](https://discourse.vtk.org/t/how-to-use-generic-window-interactor/11960/1 "2023-07-18T13:57:17Z")

</div>

How to use `vtkGenericRenderWindowInteractor`? What is it meant for (use-case)?  
The documentation of `vtkGenericRenderWindowInteractor` is light… Not sure to get when, why and how you need to use this…

Start from here: [https://examples.vtk.org/site/Cxx/Interaction/MouseEvents/](https://examples.vtk.org/site/Cxx/Interaction/MouseEvents/). All works fine. Now, replace `vtkRenderWindowInteractor` with `vtkGenericRenderWindowInteractor`:

```auto
>> git diff
diff --git a/MouseEvents.cxx b/MouseEvents.cxx
index ddba719..0b91b98 100644
--- a/MouseEvents.cxx
+++ b/MouseEvents.cxx
@@ -7,9 +7,11 @@
 #include <vtkPolyDataMapper.h>
 #include <vtkProperty.h>
 #include <vtkRenderWindow.h>
-#include <vtkRenderWindowInteractor.h>
+#include <vtkGenericRenderWindowInteractor.h>
 #include <vtkRenderer.h>
 #include <vtkSphereSource.h>
+#include <vtkCommand.h>
+#include <vtkCallbackCommand.h>
 
 namespace {
 
@@ -46,6 +48,9 @@ vtkStandardNewMacro(customMouseInteractorStyle);
 
 } // namespace
 
+void timerEventCallback(vtkObject *caller, unsigned long eventId, void *clientData, void *callData) {
+}
+
 int main(int, char*[])
 {
   vtkNew<vtkNamedColors> colors;
@@ -70,7 +75,10 @@ int main(int, char*[])
   renderWindow->AddRenderer(renderer);
   renderWindow->SetWindowName("MouseEvents");
 
- vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
+ vtkNew<vtkGenericRenderWindowInteractor> renderWindowInteractor;
+ vtkSmartPointer<vtkCallbackCommand> timerEventCommand = vtkSmartPointer<vtkCallbackCommand>::New();
+ timerEventCommand->SetCallback(timerEventCallback);
+ renderWindowInteractor->AddObserver(vtkCommand::TimerEvent, timerEventCommand);
   renderWindowInteractor->SetRenderWindow(renderWindow);

```

Looks like the windows pops up flashing and die immediately?!.. Tried to add `timerEventCallback` like suggested in the doc (but without really understanding why ?!..): no improvement…

Didn’t find any example of use:

```auto
>> git remote -v
origin	https://gitlab.kitware.com/vtk/vtk.git (fetch)
>> git grep vtkGenericRenderWindowInteractor
...

```

Doesn’t tell much…

How and when to use `vtkGenericRenderWindowInteractor`? How to make the simple code above work with it?
