Change speed of mouse cursor/tracking

could anyone help me how to change mouse speed?
I make my own class MySlider : public Slider and want to make it much more sensitive when press command/ctrl button.

Of course I know methods like:

But to be honest I don’t like the behaviour of it.
So I implemented my own “slow down” algorithm for my slider (in mouseDrag() method), and actually it works perfect, except one thing: my mouse cursor behaviour.

I want to make it slow down in the same manner as I made it for my slider in mouseDrag(), or at least to make cursor static (no move), or to make cursor disappear ( disappearing is implemented for default Slider when press command/ctrl, but it’s some too difficult code for me to understand).

Could anyone help me please?

Best Regards

The easiest solution is to hide the cursor, like you said.

In your mouseDrag() (or alternatively, override mouseDown() depending on the look/feel you’re going for), simply use:

void mouseDrag (MouseEvent& e)
    // Cursor is now hidden, do stuff...

void mouseUp (MouseEvent& e)
    // Cursor is now visible, do stuff...

Of course, you can add your own conditional logic or whatever else you want around the show/hide cursor code.

Hey Jonath, thanks for your reply.
It looks nice what you’ve shown. But probably my lack of C++ skills doesn’t let me use that.

mouseDrag()is a virtual function with input parameter const MouseEvent& e (not MouseEvent& e as you showed). So I get error:

cannot convert ‘this’ pointer from ‘const juce::MouseInputSource’ to ‘juce::MouseInputSource &’

So I tried to not override but overload that method exactly as you showed. But then it is not recognize - it compile but when I dragging it is not called.

Could you give some more advices, please ? :slight_smile:

To be clear my slider class looks like that:

class MySlider : public Slider
    // bla bla bla 

class MySpecialSlider : public MySlider
    // and here I have my mouseDrag()
    void mouseDrag(MouseEvent& e)

Whoops, you’re right; since the MouseEvent argument is const, I think calling hideCursor() and showCursor() might be invalidating that.

My JUCE skills are very rusty. Hopefully another person can come in and assist, but I recommend churning through whatever Slider is doing internally to hide/show the cursor.

The easy solution is, to get the MouseInputSource from the desktop using getMainMouseInputSource():

if (auto* source = Desktop::getInstance().getMainMouseSource())

the dirty solution is a const_cast, and the overkill solution is, to iterate all MouseInputSources and see, which one did trigger.

1 Like