# \[javascript\] vtkRenderWindowInteractor doesn't have the function addObserver

**URL:** https://discourse.vtk.org/t/javascript-vtkrenderwindowinteractor-doesnt-have-the-function-addobserver/11624
**Category:** Support
**Created:** [June 7, 2023, 10:19am UTC](https://discourse.vtk.org/t/javascript-vtkrenderwindowinteractor-doesnt-have-the-function-addobserver/11624 "2023-06-07T10:19:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [June 7, 2023, 10:19am UTC](https://discourse.vtk.org/t/javascript-vtkrenderwindowinteractor-doesnt-have-the-function-addobserver/11624/1 "2023-06-07T10:19:40Z")

</div>

I want to associate a mousemove event handler to an interactor. this is done in python as

```auto
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.AddObserver("MouseMoveEvent", mousemove)

```

The problem is that this function doesn’t exist in vtk.js. Is there any way to achieve this?  
I am currently using the container of the interactor `container.addEventListener('mousemove', mousemove);`. But this creates some conflict with current mousemove events (when some manipulator is activated).

Is there a right way of doing this?

My mousemove function is

```auto
performanceTimer=performance.now();

function mousemove(event){
    // If any interactor is active or mouse moves too fast do nothing
    if ((performance.now()-performanceTimer<10) || interactor.getInteractorStyle().currentManipulator){
        return;
    } else {
        // Do stuff
        performanceTimer=performance.now();
    }
}

```

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [June 7, 2023, 3:38pm UTC](https://discourse.vtk.org/t/javascript-vtkrenderwindowinteractor-doesnt-have-the-function-addobserver/11624/2 "2023-06-07T15:38:43Z")

</div>

vtkRenderWindowInterator trigger [the following set of events](https://github.com/Kitware/vtk-js/blob/master/Sources/Rendering/Core/RenderWindowInteractor/index.js#L28-L66).

So you should be able to do the following

```js
const subscription = renderWindowInteractor.onMouseMove(mousemove);

```

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [June 8, 2023, 8:49pm UTC](https://discourse.vtk.org/t/javascript-vtkrenderwindowinteractor-doesnt-have-the-function-addobserver/11624/3 "2023-06-08T20:49:27Z")

</div>

Hello and thanks

Main question:  
Does this onMouseMove come with a throttler, or do I have to make my own hack?

The main problem I have now is that my throttler messes up with the interactor event and the interaction happens only every number of ms (if I decrease them then the system halts with many calls to mousemove, if I increase it all the interactors became laggy)

I need to display the scalar contained int the cell under the mouse, but if any interactor is activated, then don’t trigger this mouse move function.

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [June 8, 2023, 10:11pm UTC](https://discourse.vtk.org/t/javascript-vtkrenderwindowinteractor-doesnt-have-the-function-addobserver/11624/4 "2023-06-08T22:11:30Z")

</div>

You can [throttle](https://github.com/Kitware/vtk-js/blob/master/Sources/macros.js#L1131-L1154) the mousemove callback by decorating it.

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [June 9, 2023, 11:37am UTC](https://discourse.vtk.org/t/javascript-vtkrenderwindowinteractor-doesnt-have-the-function-addobserver/11624/5 "2023-06-09T11:37:36Z")

</div>

I have solved the interaction conflict by changing this `interactor.getInteractorStyle().currentManipulator` into `event.button>=0`. Everything is working as intended now.

Somehow the current manipulator way is not working
