I would like to detect mouse moving, while the left button is pressed.
I simply create a drawing application. I can detect the mouse move without any mouse pressed. But I want to detect WITH left mouse pressed.
I think there is not any listener for this. So, what is the idea to do that?
JavaScript is implemented as part of a Web browser and is supported by all the major web browsers, including Internet Explorer, Firefox and Safari. Therefore, using this language, Web developers can track user's mouse movements simply by entering lines of code on a page.
We can listen to the mousedown and mouseup events to check if a mouse button is kept down after we press the mouse button. We set the window. onmousedown and window. onmouseup properties to functions that change the mouseDown count to listen for the mousedown and mouseup events on the whole tab.
component.addmouseMotionListener(new MouseAdapter() {
public void mouseDragged(MouseEvent evt) {
if ( SwingUtilities.isLeftMouseButton(evt)) {
// do your stuff here
}
}
});
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