User Code: Mouse Hex Value Check

Thursday Apr 19th 2001 by Corey Livermore
Share:

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 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 kmurphy@internet.com.]

Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved