Simulate mouse actions



I’m writing a Max external using an embedded Juce-rendered GUI . To do this, I am rendering to juce::Graphics and grabbing bitmap data to paste in to Max’s graphics context, as described in this thread - it’s a little hacky, but it works and I don’t see any other option.

That’s all working fine. The trouble I’m now faced with is passing back the mouse events from Max so that I can just rely on Juce to resolve the actioned Component and call the relevant listener. The Max API gives me a bunch of mouse event methods with which I was hoping to just call the relevant handlers in Juce as if the event had occurred on my Juce-rendered GUI rather than on my Max bitmap-copy of the GUI - I’m just not sure of the best way to do this. My solution needs to remain platform independent.

Any help would be much appreciated.


If you’ve got the ComponentPeer for the window that you want to forward the mouse events to then you can use ComponentPeer::handleMouseEvent().

The Unity plug-in wrapper does something similar so you might want to check that out for some ideas - specifically the mouse handler callbacks here.


Thanks for that. I’d looked at ComponentPeer but my component doesn’t have one as I don’t addToDesktop(). I tried hacking about to manually createNewPeer(), but it wasn’t quite that simple. I followed the code through the debugger to figure out why coordinates were not resolving to components and ended up hacking about a bit more until I figured it was all getting too messy and there must be a better way.


The component should still have a peer as it’ll be in a window that’s on the desktop. You can get the peer by doing something like:

if (auto* peer = yourComponent.getPeer())
   // forward your mouse events here...