# Trackpad right-button key modifier?

**URL:** <https://forum.juce.com/t/trackpad-right-button-key-modifier/52714>\
**Category:** General JUCE discussion\
**Created:** [August 23, 2022, 4:35pm UTC](https://forum.juce.com/t/trackpad-right-button-key-modifier/52714 "2022-08-23T16:35:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![alejocazu](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@alejocazu](https://forum.juce.com/u/alejocazu)\
**Post date:** [August 23, 2022, 4:35pm UTC](https://forum.juce.com/t/trackpad-right-button-key-modifier/52714/1 "2022-08-23T16:35:57Z")

</div>

I am trying to add a “right click” popup menu to a button, and while isPopupMenu works with a mouse (right-click) and with control-click (on mac), it doesn’t work with the “two-finger tap” of my MacBook’s trackpad.

Isn’t the two-finger tap supposed to be right-click? it is for every app on the Mac… How can I intercept the two-finger tap to add it as a modifier?

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [August 24, 2022, 4:01pm UTC](https://forum.juce.com/t/trackpad-right-button-key-modifier/52714/2 "2022-08-24T16:01:18Z")

</div>

Could you provide a minimal example that demonstrates the issue. I’ve never had any problem with “two-finger tap” on a Mac.

---

<div class="post-metadata">

**Author:** ![alejocazu](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@alejocazu](https://forum.juce.com/u/alejocazu)\
**Post date:** [August 24, 2022, 4:15pm UTC](https://forum.juce.com/t/trackpad-right-button-key-modifier/52714/3 "2022-08-24T16:15:59Z")

</div>

So apologies if my code is choppy, still learning…

I have a drawable button, onClick I send a DBG message, if isPopupMenu, I send an extra DBG message, on mac, two-finger tap doesnt work, but CTRL+click works fine.

```auto
   midiButton->onClick = [this] {
        DBG("lal");
        if (juce::ModifierKeys::getCurrentModifiers().isPopupMenu())
            DBG("lol");
    };

```

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [August 24, 2022, 4:34pm UTC](https://forum.juce.com/t/trackpad-right-button-key-modifier/52714/4 "2022-08-24T16:34:16Z")

</div>

Hmm, something funky going on here that may well be a bug.

100% sure that testing `MouseEvent.mods.isPopupMenu()` in `mouseDown` or `mouseUp` methods of a `Component` (or derived class) works as intended, but I never used `onClick` beyond implementing left click behaviours.

Looking quickly at the JUCE code seems like this _should_ work in `onClick` for a `Button`, but I don’t have time to investigate further.

---

<div class="post-metadata">

**Author:** ![alejocazu](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@alejocazu](https://forum.juce.com/u/alejocazu)\
**Post date:** [August 24, 2022, 7:52pm UTC](https://forum.juce.com/t/trackpad-right-button-key-modifier/52714/5 "2022-08-24T19:52:08Z")

</div>

OK SO I just used the MouseDown method and I confirm it works correctly, meaning the onClick must have a bug

```auto
void mouseDown(const juce::MouseEvent& e)
{
    if (e.eventComponent==midiButton.get())
        if (e.mods.isPopupMenu())
            DBG("lol");
}
```

So just an “etiquette” question, since onClick is buggy, should I just always stick to listeners and mouseDown, or should I use onClick for left clicks and mouseDown for the rest?

---

<div class="post-metadata">

**Author:** ![yfede](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yfede/32/506_2.png) [@yfede](https://forum.juce.com/u/yfede)\
**Post date:** [August 25, 2022, 8:32am UTC](https://forum.juce.com/t/trackpad-right-button-key-modifier/52714/6 "2022-08-25T08:32:10Z")

</div>

Please be aware that adding a MouseListener for intercepting the right mouse click is only half of the problem: the Button that you right-clicked will still perform its action exactly as if it were left-clicked, and that may not be what you wanted/your user expects when right-clicking to display its context menu.

To prevent the left-click action being triggered when right-clicking, there are a number of workarounds (listed in the topic linked below), but IMHO it would be better for JUCE Buttons to natively have an option to ignore right-clicks (or hey, even provide a `onRightClick` lambda for them, that would be awesome) so if you agree, please cast your vote in the Feature Request topic linked below, perhaps that will catch the JUCE team attention…

> [@\[FR\] Buttons: add option to ignore clicks with right mouse button](https://forum.juce.com/t/fr-buttons-add-option-to-ignore-clicks-with-right-mouse-button/20723/):
>
> What I wish to do is have a Button display a context menu when right-clicked. A MouseListener attached to it takes care of displaying the PopupMenu just fine. The problem is that the Button still receives its “click” event when the right mouse button acts upon it, which is something I don’t want in my use case. Would it be possible to add an option to the base Button class to avoid that? EDIT: if it is of any help, this is the patch with which I have hardcoded that behavior (left-click only)…

---

<div class="post-metadata">

**Author:** ![crandall1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/crandall1/32/157_2.png) [@crandall1](https://forum.juce.com/u/crandall1)\
**Post date:** [December 4, 2022, 1:17pm UTC](https://forum.juce.com/t/trackpad-right-button-key-modifier/52714/7 "2022-12-04T13:17:41Z")

</div>

This right click disparity has not yet been addressed, and it needs to be. On a modern Macbook or MBP, right click _DEFAULTS_ to cmd-click for system right click. The user needs to activate the two-finger right click (which is the right click that JUCE recognizes) in trackpad settings.

I shouldn’t have to add a special case for cmd-click-if-you’re-on-a-Mac-with-a-trackpad.

---

<div class="post-metadata">

**Author:** ![crandall1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/crandall1/32/157_2.png) [@crandall1](https://forum.juce.com/u/crandall1)\
**Post date:** [December 4, 2022, 1:21pm UTC](https://forum.juce.com/t/trackpad-right-button-key-modifier/52714/8 "2022-12-04T13:21:46Z")

</div>

Note this also happens if the user has a Magic Mouse connected, as it also defaults to cmd-Click for right click.

Fucking Apple.
