Mac beep sound with menu items and keyboard shortcuts

I’m having some issues with the beep / alert sound on Mac, I mean the sound you get in Finder when you press a key shortcut that doesn’t do anything. The sound plays with some menu items in my application (doesn’t play with others), which seems to depend on the position / index of the menu item. It also plays when I forward key events from my main window to my MidiKeyboardComponent like so:

bool MyMainWindow::keyStateChanged(bool isKeyDown) {
    return midiKeyboardComponent->keyStateChanged(isKeyDown);
}

Even if I return true from my keyStateChanged, the sound still plays. But only if the forwarding actually happens, not when the MidiKeyboardComponent has keyboard focus.

My question is: When does Juce (or OSX) decide to play the sound? What does it depend on and what can I do to prevent it?

How can I avoid the sound from getting played when pressing keys or clicking menu items?

The beep is generated in LookAndFeel::playAlertSound() - if you never want any beeps, you can override that in your own default L+F to silence it completely.

Or just make sure that your top-level component consumes all the unwanted keypresses, because the beep is telling you that a keypress has been unused.

Thanks for your help!

Those beeps don’t seem to be generated in LookAndFeel::playAlertSound(). Here’s what I have:

class GlobalLookAndFeel : public juce::LookAndFeel_V3 {
public:
    void playAlertSound() override {}
};

I’m using this as the default LookAndFeel by calling setDefaultLookAndFeel. The beep is playing like before, and playAlertSound never gets called in the cases I described. I have other LookAndFeel classes, but they all inherit from GlobalLookAndFeel, and none of them overrides playAlertSound().

Consuming all the unwanted keypresses fixes the problem for keypresses, but not for menu items. How can I fix those?

Sorry to wake up an old thread, but this doesn’t seem to work.

Overriding LookAndFeel::playAlertSound() does not work. It never seems to hit.

For example, when you launch a JUCE App, by default, pressing keys generates the beep sound. I’ve put this in my LookAndFeels. But this override never hits.

Let’s say you wanted to play a custom alert sound, everywhere that JUCE does a beep? What is the trick for this?