# Ho to check for left button single click event vs click and drag event

**URL:** https://discourse.vtk.org/t/ho-to-check-for-left-button-single-click-event-vs-click-and-drag-event/3629
**Category:** Support
**Created:** [June 24, 2020, 5:39am UTC](https://discourse.vtk.org/t/ho-to-check-for-left-button-single-click-event-vs-click-and-drag-event/3629 "2020-06-24T05:39:34Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dwventer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dwventer/32/1579_2.png) [@dwventer](https://discourse.vtk.org/u/dwventer)
#### Post date: [June 24, 2020, 5:39am UTC](https://discourse.vtk.org/t/ho-to-check-for-left-button-single-click-event-vs-click-and-drag-event/3629/1 "2020-06-24T05:39:34Z")

</div>

I have a view with a vtkInteractorStyleTrackballCamera interactor. When you drag the mouse (left click and drag) it rotates the object. This is good. Now I want to return the mouse coordinates when the user does a single left button click and release.

At the moment, when I add a vtkCallbackCommand with the vtkCommand::KeyPressEvent the rotational ability of the object gets disabled. Any thoughts?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 27, 2020, 9:11pm UTC](https://discourse.vtk.org/t/ho-to-check-for-left-button-single-click-event-vs-click-and-drag-event/3629/2 "2020-06-27T21:11:51Z")

</div>

Hi, Daniel,

Do you extend `vtkInteractorStyleTrackballCamera`? If so, you need to forward the event to the superclass: `vtkInteractorStyleTrackballCamera::OnLeftButtonDown();` in your class if you wish to maintain the original behavior in addition to the one of your code.

regards,

Paulo

---

<div class="post-metadata">

### Author: ![dwventer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dwventer/32/1579_2.png) [@dwventer](https://discourse.vtk.org/u/dwventer)
#### Post date: [June 28, 2020, 11:09pm UTC](https://discourse.vtk.org/t/ho-to-check-for-left-button-single-click-event-vs-click-and-drag-event/3629/3 "2020-06-28T23:09:36Z")

</div>

Hi Paulo,

Thanks for your response. I have managed to find a solution to my problem. Not sure if it is the best one but it works.

I prefer to use observers then I do not have to do the whole inheritance thing. I added a callback method to my vtkInteractorStyleTrackballCamera object using the vtkCommand::LeftButtonPressEvent and the vtkCommand::LeftButtonReleaseEvent (on the same method).

I then record the mouse pointer location on the LeftButtonPressEvent and compare it to when the mouse button is released (LeftButtonReleaseEvent). If they match I then do my stuff. That is it.

Regards,  
Daniel

---

<div class="post-metadata">

### Author: ![KaiHarvert](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/cdc98d/32.png) [@KaiHarvert](https://discourse.vtk.org/u/KaiHarvert)
#### Post date: [July 23, 2024, 8:05am UTC](https://discourse.vtk.org/t/ho-to-check-for-left-button-single-click-event-vs-click-and-drag-event/3629/4 "2024-07-23T08:05:30Z")

</div>

Hi, Paulo.I have a question. I Do not extend `vtkInteractorStyleTrackballCamera`,because I use C# program Kitware.VTK.When I drag the mouse (left click and drag) it rotates the object,but the event function: renWinInteractor.LeftButtonReleaseEvt+=LeftButtonReleaseEvt can not capture Button Release at once , As you say,in C++ program ,just need to forward the event to the superclass: `vtkInteractorStyleTrackballCamera::OnLeftButtonDown()`,I want to know how to realize this in Kitware.VTK using event function  
regards

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [July 23, 2024, 7:20pm UTC](https://discourse.vtk.org/t/ho-to-check-for-left-button-single-click-event-vs-click-and-drag-event/3629/5 "2024-07-23T19:20:40Z")

</div>

Hello,

You first need to derive `vtkInteractorStyleTrackballCamera` to “forward the event to the superclass”. C# certainly has an inheritance mechanism.

best,

PC

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [July 24, 2024, 7:52pm UTC](https://discourse.vtk.org/t/ho-to-check-for-left-button-single-click-event-vs-click-and-drag-event/3629/6 "2024-07-24T19:52:36Z")

</div>

Not sure about what’s available from Kitware’s C# VTK. If you’re doing it without extending the interactor style, it is best to listen to the interactor for events and then forward the event to the interactor style.

Here’s an example in C++, it should apply to Python and C# assuming VTK C# exposes the enums from `vtkCommand` and functions from interactor style.

```cpp
void OnLeftButtonDown(....)
{
   // ...
   // switch style could be a special case, so just to be safe, let's handle it.
   auto* style = vtkInteractorStyle::SafeDownCast(interactor->GetInteractorStyle());
   if (auto* switchableStyle = vtkInteractorStyleSwitch::SafeDownCast(style))
   {
      switchableStyle->GetCurrentStyle()->OnLeftButtonDown();
   }
   else
   {
      style->OnLeftButtonDown();
   }
}

void OnLeftButtonUp(....)
{
   // ...
   // switch style could be a special case, so just to be safe, let's handle it.
   auto* style = vtkInteractorStyle::SafeDownCast(interactor->GetInteractorStyle());
   if (auto* switchableStyle = vtkInteractorStyleSwitch::SafeDownCast(style))
   {
      switchableStyle->GetCurrentStyle()->OnLeftButtonUp();
   }
   else
   {
      style->OnLeftButtonUp();
   }
}
interactor->AddObserver(vtkCommand::LeftButtonPressEvent, OnLeftButtonDown);
interactor->AddObserver(vtkCommand::LeftButtonReleaseEvent, OnLeftButtonUp);

```

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [July 31, 2024, 6:53pm UTC](https://discourse.vtk.org/t/ho-to-check-for-left-button-single-click-event-vs-click-and-drag-event/3629/7 "2024-07-31T18:53:22Z")

</div>

Hello,

In case it’s not clear, C++, I do this:

```cpp
class MyInteractor : public vtkInteractorStyleTrackballCamera {
public:
   ...
   void OnLeftButtonDown() override {
      do_my_stuff();
      // Forward the event to the base class to keep current behavior.
      vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
   }
   ...
private:
   ...
protected:
   ...
};

```

I think translating this to C# is straightforward.

best,

PC
