Guillaume
Guillaume

Reputation: 5557

Java swing: how to know the state of the mouse from outside the component receiving the event?

I want to know the state of my mouse buttons (pressed or not), from outside the target component.

I don't want to use a glasspane to intercept events.

The MouseInfo class can give me the location of the mouse, but not its state.

Is there a way of retrieving mouse state from anywhere in the application ?

Thanks.

Upvotes: 2

Views: 1029

Answers (1)

camickr
camickr

Reputation: 324118

The mouse state only changes when a MouseEvent is generated, so you need to listen for MouseEvents.

I guess you could add a global MouseListener to track the state yourself based on the last MouseEvent generated. Check out the Global Event Listeners for an example of using the AWTEventListener.

Upvotes: 2

Related Questions