tags:

views:

199

answers:

3

I'm experiencing some strange behaviour when using a stylus with swing.

I am interpreting pressing the button on the side of the stylus(RIGHT) and pressing the stylus down(LEFT) as a "Grab" event, but occasionally (more often than 0), events are just being dropped.

The JavaDocs for MouseEvent are pretty explicit about how multibutton presses are handled if executed one at a time (left down, right down, right up, left up) but say nothing about simultaneous button presses.

I'm left to wonder, would they be emitted as two mousePressed events, or as one with the button mask set for both buttons, or something else entirely?

Thanks.

+1  A: 

I'd interpret the API doc as simultaneous button presses being simply not possible:

When multiple mouse buttons are pressed, each press, release, and click results in a separate event.

So there should be separate events. The problems you observe could be due to errors in your code, the stylus' driver, the hardware, or Swing (this is in decreasing order of likelihood as I see it :)

I'd try to diagnose the problem by logging events at different levels, if possible.

Michael Borgwardt
Regarding the decreasing order of likelihood, that's usually the assumption I go with too. Problems in my code are usually misunderstandings of the Java code. Hence, this initial question after reading the docs.
Allain Lalonde
+1  A: 

Simultaneous button presses are processed as two separate mousePressed events. Run the Mouse Events Demo to see them processed separately.

Bill the Lizard
A: 

As I recall, there's no way to handle simultaneous button presses. What I used to do to ensure that multiple buttons being pressed at once were treated as such was I would have a boolean variable for each button and when it was pressed, I would set it to true and when it was released, I would set the boolean to false. Then when it came time to perform an action, I would check for the boolean variables (sometimes I would have the actionlistener redirect to the method call for determining what action was to happen next after setting the booleans). This doesn't work if the only thing you want to do is them being pressed at the exact same time, but if you're just trying to get combinations to work, then that's how I did it. This was about 4 years ago, before Java 5, so I may be wrong about that.

indyK1ng