Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect mouse moving while left button down?

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?

like image 672
Bnymn Avatar asked Dec 14 '10 20:12

Bnymn


People also ask

Can browser detect mouse movement?

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.

How can I tell if my mouse is down?

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.


1 Answers

component.addmouseMotionListener(new MouseAdapter() {
    public void mouseDragged(MouseEvent evt) {
       if ( SwingUtilities.isLeftMouseButton(evt)) {
         // do your stuff here
       }
    }
});
like image 189
Jeff Storey Avatar answered Oct 13 '22 23:10

Jeff Storey