How do I find out which mouse button is pressed for a MouseEvent?
Created May 4, 2012
John Zukowski
For AWT programs, you need to compare the modifiers of the event to the button masks of the INPUT_EVENT.
Left | InputEvent.BUTTON1_MASK |
Middle | InputEvent.BUTTON2_MASK |
Right | InputEvent.BUTTON3_MASK |
For Swing programs, the SwingUtilities class provides three support methods to do the INPUT_EVENT mask checking for you: isLeftMouseButton(), isRightMouseButton(), and isMiddleMouseButton().
The meaning of left, middle, and right assumes a right-handed mouse.
Also, keep in mind that not all users have three-button mice. While there are keyboard alternatives for the addition buttons, consider the awkwardness for users before adding the functionality.