Link to home
Start Free TrialLog in
Avatar of iphone
iphone

asked on

How to catch right and left mouse pressed at the same time?

Hi Experts..
 i wanna have 3 mouse pressed event
1st :  left mouse pressed
2nd : Right mouse Pressed
3rd : right and left mouse pressed

how can i handle my 3rd event(right and left pressed) in the same time...because as we know..we cant do it in the almost exact time..so that it would run the 1st event/2nd event first before running the 3rd event
so how does to avoid 1st/2nd even to occured before my 3rd?
Avatar of Mick Barry
Mick Barry
Flag of Australia image

don't think you can avoid it.
You'll need to add some logic to your code to handle it.
eg. checking if the other is already pressed when the other other is
And adding a slight delay to wait for the other to be pressed before processing the single press
ASKER CERTIFIED SOLUTION
Avatar of malfunction84
malfunction84
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

it has been a long time since i used java..

but please try this..

public void mouseClicked(MouseEvent e)
{
    if (e.getButton() == (MouseEvent.BUTTON1 | MouseEvent.BUTTON2) )
        // do something here
    else if (e.getButton() == MouseEvent.BUTTON1 )
        // do something here    
    else if (e.getButton() == MouseEvent.BUTTON2 )
        // do something here
}

           
Avatar of iphone
iphone

ASKER

Thx for your guys quick replies
but think malfunction84 thrown something for me to think on it