Using Timer on keeping mouse down

I want to have some navigation buttons, so for example button “left”, and when I click it and keep button down I want my component move smoothly to the left, and when I release mouse button I want to stop mooving.
I consider to use Timer and then start timer on mouseDown, and stop it on mouseUp.

But I wonder maybe there is some ready to use virtual method that I can just override.
Some method that is calling continously (in some while loop or in some timer callback) when I keep mouse button down?

How would you solve my issue? Is there anything better than Timer?

This might help:

1 Like

Hey, thanks for that reply. It looks interesting.
But actually for make my question clearer I little bit lied :slight_smile:

I am not going to use Button, I want that behaviour on Component when mouseDrag and when mouse XY goes outside some bounds I want to start that repeating method and return from mouseDrag and keep repeating until mouse XY is out of bounds AND mouse button is down AND independently if I still drag or just not.

So i will consider to inherit from button and then use setRepeatSpeed(), or I will stay with my idea to use Timer.

Or you look how the Button class is doing what you want, and apply the same to your Component. However, it will come down to start a Timer when the user clicks and call your method regularly.

Sorry, English is not my first language, and I am not sure what you mean by “come down”?
Does it mean my plugin will be slower or less optimize? Or what?
And will it “come down” only when user clicks regularly? But if user call it only once it will not come down?
It sounds for me little bit mysterious. Sorry google translator does not work in that case.

It’s just an English idiom, in this instance meaning that the inevitable outcome is that you will start a Timer when the user clicks.

1 Like

Hah, OK, thanks. I am stupid :slight_smile: