Detecting mouse buttons

D

Daniel Tahin

Hi all!

How can i determine, which mouse button was pressed, using
java.awt.Event class (JDK1.0 API)?
I write following for the left button:
if( e.modifiers!=Event.ALT_MASK && e.modifiers!=Event.META_MASK ) {
doSomething();
}
//all these things are inside of handleEvent(Event e) {}, and i extend
java.awt.Canvas.

This seems to be working for the left button, BUT there is only 1
problem. If i use the scroller, doSomething() will be invoked as well
(the mouse has 2 buttons, and a scroller).


Do you know any solution for this problem?
Thanx in advance,
Daniel
 
S

Stefan Schulz

Hi all!

How can i determine, which mouse button was pressed, using
java.awt.Event class (JDK1.0 API)?
I write following for the left button:
if( e.modifiers!=Event.ALT_MASK && e.modifiers!=Event.META_MASK ) {
doSomething();
}
//all these things are inside of handleEvent(Event e) {}, and i extend
java.awt.Canvas.

This seems to be working for the left button, BUT there is only 1
problem. If i use the scroller, doSomething() will be invoked as well
(the mouse has 2 buttons, and a scroller).

Just guessing here, but the proper idom would likely be

( (e.modifiers & Event.ALT_MASK) != 0
&& (e.modifiers & Event.META_MASK)!= 0)

since there might be both ALT and META active.
 
S

Stefan Schulz

Just guessing here, but the proper idom would likely be

( (e.modifiers & Event.ALT_MASK) != 0
&& (e.modifiers & Event.META_MASK)!= 0)

since there might be both ALT and META active.

Erg. make that == in both cases. We are checking for absence of the flags,
not presence.
 
J

Joan

Daniel Tahin said:
Hi all!

How can i determine, which mouse button was pressed, using
java.awt.Event class (JDK1.0 API)?

I might be mistaken, but I don't think the mouse wheel was invented back
then.
 
D

Daniel Tahin

Yes, this is OK for scanning the left button, but the previous problem
is still there:-((
 
T

Tom N

Daniel said:
How can i determine, which mouse button was pressed, using
java.awt.Event class (JDK1.0 API)?
I write following for the left button:
if( e.modifiers!=Event.ALT_MASK && e.modifiers!=Event.META_MASK ) {
doSomething();
}
//all these things are inside of handleEvent(Event e) {}, and i extend
java.awt.Canvas.

This seems to be working for the left button, BUT there is only 1
problem. If i use the scroller, doSomething() will be invoked as well
(the mouse has 2 buttons, and a scroller).

Mouse events are actually java.awt.event.MouseEvent.

Call java.awt.event.MouseEvent.getButton()

result 1 = left button
2 = scroll wheel (middle button)
3 = right button

You might need to call canvas.addMouseListener(new MySubClassOfMouseAdapter())
 
R

Roedy Green

This seems to be working for the left button, BUT there is only 1
problem. If i use the scroller, doSomething() will be invoked as well
(the mouse has 2 buttons, and a scroller).


Do you know any solution for this problem

Have a read of my general essay on the problem. see
http://mindprod.com/jgloss/event11.html

I can't figure out just what it is your are asking.

In these sorts of problem. your first task it to makes you are seeing
the event, and not to many other events -- ie. that you are tapping
the right place with the right sort of listener.

Once you have that established, then start thinking about how to
filter your events.

You normally don't meddle at the low level you are proposing.



--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
D

Daniel Tahin

Roedy said:
Have a read of my general essay on the problem. see
http://mindprod.com/jgloss/event11.html


A great site. Is it possible to download the complete site for offline use?

I can't figure out just what it is your are asking.


Eevrything worked fine with handleEvent(), but it seems for me, that
jdk1.3 under Linux interpret the scroller of the mice, as the left
button (scrolling has the same effect, as pressing the left button.
Curious, because the wheel mouse support was introduced first in java 1.4).
I solved the problem by not using the left button... :-(
Now everything is ok.

In these sorts of problem. your first task it to makes you are seeing
the event, and not to many other events -- ie. that you are tapping
the right place with the right sort of listener.

Once you have that established, then start thinking about how to
filter your events.

You normally don't meddle at the low level you are proposing.


cu,
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top