I would like to know if there exists in Java an event that is continuously fired when a mouse button is being held down (pressed), even if the mouse is not moved. I could not find it in typical MouseListeners:
And that's about it. Any idea how to make such an event?
Cheers
jy
There is an obvious reason why this event is not available in MouseListener: it's going to spam you with events such that everything is slowed down to a halt. Do you want to receive this event every second, every ms, or even more often? If you need that you'll have to do it yourself.
For stearing this process you of course need mousePressed
and mouseReleased
to determine whether a button is currently held down. Then you need to run some kind of loop that generates the corresponding events you'd like to have.
You might also want to work via polling, i.e. extend your MouseListener class such that it can tell you whether a button is still held down, and whereever you need those events you can actively poll for the button. It depends on how you want to use these events, which approach is more suitable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With