How to listen to mouse wheel disks?

Is there a way to listen to the wheels of the mouse wheel (without moving the wheel, just pressing it)?

I checked the MouseWheelListener API, but there is nothing on the wheels of the mouse wheel, just moving the wheels.

+5
source share
2 answers

Mouse button - usually mouse button 2:

public void mouseClicked(MouseEvent evt) {

    if ((evt.getModifiers() & InputEvent.BUTTON2_MASK) != 0) {
      System.out.println("middle" + (evt.getPoint()));
    }

 }

or even better:

SwingUtilities.isMiddleMouseButton(MouseEvent anEvent)
+8
source

Mouse wheel presses communicate through the interface MouseListener.

Use the events mousePressedand mouseReleasedand check the method MouseEvent.getButton()to return the number of the button pressed or released.

mouseClicked, , . , , , MouseEvent.getModifiers() .

+1

All Articles