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