How do I find out which mouse button is pressed for a MouseEvent?

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.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact