Locking the mouse and making it invisible when using a slider?

Hi, in my plugin I have quite a lot of slider, but I want the slider the mouse to disappear and stay in the exact same position as I’m interacting with the slider, like how Ableton does it. However I have not been able to find a suitable function/method that fits my needs. The closest thing I have is doing this:

void MySlider::mouseDown(const juce::MouseEvent& m)


void MySlider::mouseUp(const juce::MouseEvent& m)


However this does not achieve the behaviour I am after. The mouse does disappear but it moves slightly after I have finished interacting with the slider. I want it to return to the exact same position that it started at.


In the MouseDown Callback you could save the position (savedPoint = juce::getMousePosition()) and in the MouseUp do juce::setMousePosition(savedPoint).

But I suggest to test this on all OSes. There could be diffenrent behavior.

thanks, I’ll give it a try. I didn’t know these methods existed

Is there a way for the mouse-cursor to stay frozen, but the mouse-movement still changes the value up/down?

Sorry, it is juce::Desktop::setMousePos()

Actually therefore event. source.enableUnboundedMouseMovement(true) should work.

It would be better to use the methods of MouseInputSource. You get the MouseInputSource from the event, but the event is const. You will have to do an ugly workaround. const_cast is not adviseable, so what I do is find the non-const version of the event.source and work with that:

for (auto& source : juce::Desktop::getInstance().getMouseSources())
    if (source == event.source)
        source.setPosition (..);
        // ...

Would be nice to have a way to get this from the event directly…

1 Like

enableUnboundedMouseMovement() does not work unfortunately, the mouse does not return to the same position. It shifts slightly.

Yes, IIRC the cursor position is clipped back within the Slider’s bounds from where it would have been dragged if it was visible, so it won’t be too distant from where the mouseDown happened, but no further effort is made to bring it back exactly there.