• Post Reply Bookmark Topic Watch Topic
  • New Topic

tracing mouse button click (left-middle-right)

 
Sanjay Vhavlle
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I am using mouse listener interface in a simple java applete. I could trave all the mouse events, eg. the click event. But I want to trace which button is pressed, eg. left - middle - right
how can i trace the button from click event. Is there any 1 who can help me out. Thanks in advance

Sanjay
 
mark bernard
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to use the method getModifiers():
public void mousePressed(MouseEvent e) {
if(e.getModifiers()==InputEvent.BUTTON1_MASK) {
System.out.println("Left button");
}
if(e.getModifiers()==InputEvent.BUTTON2_MASK) {
System.out.println("Center button");
}
if(e.getModifiers()==InputEvent.BUTTON3_MASK) {
System.out.println("Right button");
}
}
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!