Software Development

User Code: Mouse Hex Value Check

By Corey Livermore

Here's how to determine which mouse button has been pressed.

This simple routine will check the Hex value of the mouse button being pressed and will send output to the system output telling you which button has been pressed. This can be changed so you can have other tasks done when the left or right mouse button is pressed. Note: This only works for two-button mice.

 private void Form2_mouseDown(Object source, MouseEvent e)
 {
 int Mouse = e.button;
 Integer MyMouse = new Integer(Mouse);
 String MouseHex = MyMouse.toHexString(Mouse);
 String MouseL = "1000000";

 if (MouseHex.compareTo(MouseL) < 0)
 {
 System.out.println("Left Mouse Button");
 }
 else
 {
 System.out.println("Right Mouse Button.");
 }
 }

That's it.

[To contribute a code article to Gamelan, please contact [email protected].]

April 19, 2001


View Your Site In 14 Browser & Computer Combinations!

EarthWeb is a service of internet.com Corporation.
Copyright 2001 internet.com Corp. All Rights Reserved.
Advertising Info,  Legal Notices,  Feedback,  Licensing,  Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/