Search code examples
javaswingawtmouseeventkeystroke

KeyStroke equivalant class for Mouse in Java 6?


Is there a Mouse equivalent class for KeyStroke? I'm looking for some kind of wrapper around a a MouseEvent to describe which button was pushed (I can get this through SwingUtilities), and any modifiers used as well. The idea is I'm already catch AWT mouse events through a listener, but then taking that event and processing it for 3D picking in a virtual world. I'd like to try and map mouse bindings in such a way (similar to InputMap and ActionMap with swing controls). KeyStroke has been a god-send, anyone know of a MouseStroke or similar?


Solution

  • A "mouse" is traditionally defined as having a maximum of three buttons. That is also what Java supports by MouseEvent.getButton().

    More advanced mice with multiple buttons are usually installed as multiple HID devices. Meaning they install two drivers, for a mouse AND for a keyboard. For these mice, you can set what other buttons mean, and usually it's something like a key press (for example, shift) or double click. Those are events that Java can catch, either as MouseEvent of KeyEvent.

    More advanced functionality, such as "Open an application" or "change DPI", is implemented in the driver. Being device-specific, there is nothing Java can do to catch those events (you would have to write your own native listener for these events, provided the driver support that).