# Catch right mouse click in a control

**URL:** <https://iplug2.discourse.group/t/catch-right-mouse-click-in-a-control/553>\
**Category:** Uncategorized\
**Created:** [28 January 2022 20:10 UTC](https://iplug2.discourse.group/t/catch-right-mouse-click-in-a-control/553 "2022-01-28T20:10:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![olawistedt](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olawistedt/32/232_2.png) [@olawistedt](https://iplug2.discourse.group/u/olawistedt)\
**Post date:** [28 January 2022 20:10 UTC](https://iplug2.discourse.group/t/catch-right-mouse-click-in-a-control/553/1 "2022-01-28T20:10:34Z")

</div>

I have a control that inherits from IBSwitchControl. In my OnMouseDown() I try to catch a mouse right click with if(mod.R) but it does not work. I can catch a left mouse click with if(mod.L).

Any ideas? Someone?

---

<div class="post-metadata">

**Author:** ![stw](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@stw](https://iplug2.discourse.group/u/stw)\
**Post date:** [29 January 2022 07:43 UTC](https://iplug2.discourse.group/t/catch-right-mouse-click-in-a-control/553/2 "2022-01-29T07:43:42Z")

</div>

Try to:  
#define IGRAPHICS\_NO\_CONTEXT\_MENU  
But remember that you’ll lose some plug format and host dependent right click compatibility.

---

<div class="post-metadata">

**Author:** ![olawistedt](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olawistedt/32/232_2.png) [@olawistedt](https://iplug2.discourse.group/u/olawistedt)\
**Post date:** [29 January 2022 10:44 UTC](https://iplug2.discourse.group/t/catch-right-mouse-click-in-a-control/553/3 "2022-01-29T10:44:45Z")

</div>

Aha! Thanks. It is a context menu I am trying to create. So I guess I should dig in on how to use the API for that.

---

<div class="post-metadata">

**Author:** ![stw](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@stw](https://iplug2.discourse.group/u/stw)\
**Post date:** [29 January 2022 11:13 UTC](https://iplug2.discourse.group/t/catch-right-mouse-click-in-a-control/553/4 "2022-01-29T11:13:22Z")

</div>

The define prevents the right click capture in OnMouseDown() in IGraphics.cpp if an IControl is associated to a ParamIdx. You can find some further ContextMenu info in IControl.h:

```auto
virtual void CreateContextMenu(IPopupMenu& contextMenu)

  /** Called by default when the user right clicks a control.
If IGRAPHICS_NO_CONTEXT_MENU is enabled as a preprocessor macro right clicking control will mean IControl::CreateContextMenu()
and IControl::OnContextSelection() do not function on right clicking control.
VST3 provides contextual menu support which is hard wired to right click controls by default.
You can add custom items to the menu by implementing IControl::CreateContextMenu() and handle them in IControl::OnContextSelection().
In non-VST 3 hosts right clicking will still create the menu, but it will not feature entries added by the host. */

```

---

<div class="post-metadata">

**Author:** ![olawistedt](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olawistedt/32/232_2.png) [@olawistedt](https://iplug2.discourse.group/u/olawistedt)\
**Post date:** [29 January 2022 11:53 UTC](https://iplug2.discourse.group/t/catch-right-mouse-click-in-a-control/553/5 "2022-01-29T11:53:46Z")

</div>

Thanks!

With the methods:

```auto
  void CreateContextMenu(IPopupMenu& contextMenu) override;
  void OnPopupMenuSelection(IPopupMenu* pSelectedMenu, int valIdx) override;
  void OnContextSelection(int itemSelected) override;

```

I could create what I wanted.

---

<div class="post-metadata">

**Author:** ![olawistedt](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olawistedt/32/232_2.png) [@olawistedt](https://iplug2.discourse.group/u/olawistedt)\
**Post date:** [29 January 2022 17:15 UTC](https://iplug2.discourse.group/t/catch-right-mouse-click-in-a-control/553/6 "2022-01-29T17:15:18Z")

</div>

I discovered that the context menu works fine in standalone and as vst3 but it doesn’t work in WAM.
