# How to tell if mouse is over a viewer

**URL:** <https://discourse.slicer.org/t/how-to-tell-if-mouse-is-over-a-viewer/20670>\
**Category:** Development\
**Created:** [November 18, 2021, 12:06am UTC](https://discourse.slicer.org/t/how-to-tell-if-mouse-is-over-a-viewer/20670 "2021-11-18T00:06:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![darren](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@darren](https://discourse.slicer.org/u/darren)\
**Post date:** [November 18, 2021, 12:06am UTC](https://discourse.slicer.org/t/how-to-tell-if-mouse-is-over-a-viewer/20670/1 "2021-11-18T00:06:03Z")

</div>

How can you tell if you’re on the viewer? Is there something you can test so that certain functionality is disabled when the mouse is not hovered over the viewer?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 18, 2021, 12:08am UTC](https://discourse.slicer.org/t/how-to-tell-if-mouse-is-over-a-viewer/20670/2 "2021-11-18T00:08:19Z")

</div>

You can get the current view ID and position in view and RAS coordinate systems via the crosshair singleton node. See examples in the [script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#get-current-mouse-coordinates-in-a-slice-view).

---

<div class="post-metadata">

**Author:** ![darren](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@darren](https://discourse.slicer.org/u/darren)\
**Post date:** [November 18, 2021, 7:30am UTC](https://discourse.slicer.org/t/how-to-tell-if-mouse-is-over-a-viewer/20670/3 "2021-11-18T07:30:02Z")

</div>

I see. I am currently using a crosshair node to get information from a viewer when the mouse hovers over the scan. However, after I move my mouse off of the scan/view area, the program crashes. Would this likely be something to do with the crosshair node? Or an interactor?

This only started happening after I began using the crosshair node. Specifically, after I call a line that uses -\>GetCursorPositionXYZ(xyz);

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 18, 2021, 3:34pm UTC](https://discourse.slicer.org/t/how-to-tell-if-mouse-is-over-a-viewer/20670/4 "2021-11-18T15:34:17Z")

</div>

I could not reproduce the crash using the latest Slicer Preview Release. If you can create a small standalone example that reproduces the problem then I can investigate.
