Mouse click sound effects


11-08-2012 16:06:49

What would be the best way to get a small "click" sound effect when clicking on e.g. buttons? I want to avoid having the "play sound" code in every mouseButtonClicked event callback that I have. Is there a way to have a global listener that notifies me whenever a button was clicked with the mouse?

27-08-2012 07:24:53

add custom user data in layout editor
and using


27-08-2012 08:14:23

Now that would give me a callback whenever one of the widgets (that I marked specially with this user string) is loaded. Then I could add a callback for each widget easily.

However I also create some buttons in code, and would like to avoid adding extra code for each. Also it's not really nice having to mark every button with a user string, when I just want all buttons to emit a click sound.

I think I will just check the MyGUI::InputManager's mouse focus widget whenever I get a mouse click, and if it's a button, play the sound. But that will probably lead me into trouble when modal widgets are active ?

27-08-2012 08:22:43

widgets = MyGUI::LayoutManager::getInstance().load("my.layout");
for (int index = 0; index < widgets.size(); index ++)

void buttonClickSound(MyGUI::Widget* _sender)

void adviseAllButtons(MyGUI::Widget* _widget)
MyGUI::Button* button = _widget->castType<MyGUI::Button>(false);
if (button != nullptr)
button->eventMouseClick += MyGUI::newDelegate(buttonClickSound);

for (int index = 0; index < _widget->getChildCount(); index ++)


27-08-2012 08:54:16

I used this now, it works great, even with modal widgets.

bool InputManager::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
MyGUI::InputManager::getInstance().injectMousePress(mMouseX, mMouseY, MyGUI::MouseButton::Enum(id));

if (MyGUI::InputManager::getInstance ().getMouseFocusWidget () != 0)
MyGUI::Button* b = MyGUI::InputManager::getInstance ().getMouseFocusWidget ()->castType<MyGUI::Button>(false);
if (b)
MWBase::Environment::get().getSoundManager ()->playSound ("Menu Click", 1.f, 1.f);

return true;

Another advantage is that this works for skin elements that are buttons (for example scrollbar tracks) as well.