This site requires JavaScript, please enable it in your browser!
Greenfoot back
MichaelMac
MichaelMac wrote ...

2018/3/26

Mutiple Clicks On Mouse

MichaelMac MichaelMac

2018/3/26

#
Hi guys, looking for a way to check for a click of the left mouse button and the right mouse button at the same time. How would I go about doing this?
danpost danpost

2018/3/26

#
MichaelMac wrote...
Hi guys, looking for a way to check for a click of the left mouse button and the right mouse button at the same time. How would I go about doing this?
Please be more specific as to what you are looking to accomplish. The details with respect to your scenario will help in determining exactly what particular checks might be needed.
danpost danpost

2018/3/26

#
What you are looking for may be as simple as the following (but cannot be sure):
1
2
3
4
5
6
7
8
9
10
11
12
if (Greenfoot.mouseClicked(null))
{
    int btnNum = Greenfoot.getMouseInfo().getButton();
    if (btnNum == 1) // left button
    {
        ;
    }
    else if (butNum == 3) // right button
    {
        ;
    }
}
Agent40 Agent40

2018/3/27

#
danpost wrote...
MichaelMac wrote...
Hi guys, looking for a way to check for a click of the left mouse button and the right mouse button at the same time. How would I go about doing this?
Please be more specific as to what you are looking to accomplish. The details with respect to your scenario will help in determining exactly what particular checks might be needed.
I believe that he's trying to ask for some code that checks whether or not LMB and RMB are active at the same time.
danpost danpost

2018/3/27

#
Agent40 wrote...
I believe that he's trying to ask for some code that checks whether or not LMB and RMB are active at the same time.
If that is the case, using the mouseClicked method will not help in determining the down state of the buttons. Also, since only one button's action can be returned on any given act cycle, it would be very difficult to devise code that is guaranteed to work. For example, if both LMB and RMB changed states during the same act cycle, one of the buttons will not be shown to have done an action (although both actions may be detected -- this I am not sure of). At any rate, this is because the getButton method only returns a single button. Even if it returned multiple buttons, how would one determine which action went with which button?
You need to login to post a reply.