# Disable X,Y,and Z in vtkInteractorStyleImage

**URL:** https://discourse.vtk.org/t/disable-x-y-and-z-in-vtkinteractorstyleimage/2918
**Category:** Support
**Created:** [March 30, 2020, 8:01pm UTC](https://discourse.vtk.org/t/disable-x-y-and-z-in-vtkinteractorstyleimage/2918 "2020-03-30T20:01:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [March 30, 2020, 8:01pm UTC](https://discourse.vtk.org/t/disable-x-y-and-z-in-vtkinteractorstyleimage/2918/1 "2020-03-30T20:01:14Z")

</div>

I would like to disable this key events because it rotates me one image that it has one single slice. So it does not make sense.

What I did was to try:

```
auto widget = std::make_unique<QVTKResliceImageWidget>
  (parent);
auto oblique_reslice_image_viewer_ = widget->viewer();
 vtkSmartPointer<vtkRenderWindowInteractor> interactor =
  oblique_reslice_image_viewer_->GetInteractor();
interactor->GetInteractorStyle()->
RemoveObserver(vtkCommand::CharEvent)

```

But it did not work. Then I tried to override the OnChar function from the vtkInteractorStyleImage and it worked.

But the problem is that if I override the interactor style all the observers that i had in the style stopped working.

Then i found a trick to remap the key (X Y or Z) with another that it does not have any behavour linked

```
 case vtkCommand::KeyPressEvent:
{
 const int c = int(interactor->GetKeyCode());
 std::cout << "KEY=" << c;
     //Disable the keys X Y Z of the style
 if (c == 'X' || c == 'x' || c == 'Y' || c == 'y' || c == 'Z' || c == 'z') {
    interactor->SetKeyEventInformation(0, 0, '0', 0);
 }
  break;
 }

```

This works. But the problem is when the mouse is pressed the key event is not triggered by my observer. And then i have the same issue rotating a 2d image so it becomes a black screen.

Any other way to disable X,Y and Z in the vtkInteractorStyleImage?

Thanks

---

<div class="post-metadata">

### Author: ![yangyang117](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/da6949/32.png) [@yangyang117](https://discourse.vtk.org/u/yangyang117)
#### Post date: [December 19, 2023, 2:03am UTC](https://discourse.vtk.org/t/disable-x-y-and-z-in-vtkinteractorstyleimage/2918/2 "2023-12-19T02:03:56Z")

</div>

Hi, this link can solve the problem.

> [@Disable interactions of interactor in python](https://discourse.vtk.org/t/disable-interactions-of-interactor-in-python/6939):
>
> I use vtk in an application (qt) where I would like to define my own events for right-mouse button (context menu) as well as some of the key presses. Problem is that they are already used by the interactor. ([https://vtk.org/doc/nightly/html/classvtkInteractorStyle.html#details](https://vtk.org/doc/nightly/html/classvtkInteractorStyle.html#details)) Is there a way to keep the interactor from handling these events? I’m using python so subclassing the interactor (like sugested here: [Selectively disable and enable default mouse interactions in vtk](https://discourse.vtk.org/t/selectively-disable-and-enable-default-mouse-interactions-in-vtk/2338)) is not an option. …
