March 3, 2021
Hot Topics:

User Code: Mouse Hex Value Check

  • By Corey Livermore
  • Send Email »
  • More Articles »

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");
 System.out.println("Right Mouse Button.");

That's it.

[To contribute a code article to Gamelan, please contact kmurphy@internet.com.]

This article was originally published on April 19, 2001

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date