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

2017/10/8

Detect mouse click (s)

Venbha Venbha

2017/10/8

#
Hello. I do know the code for mouse clicks..... But can you giveve code for light-click and left-click? :-]
Venbha Venbha

2017/10/8

#
Venbha wrote...
But can you giveve code for light-click and left-click? :-]
*Give *Right click
Super_Hippo Super_Hippo

2017/10/8

#
Check the MouseInfo API. You will find the 'getButton' method. 1 is the left button and 3 is the right button.
Venbha Venbha

2017/10/8

#
How to apply it on the code window? (A sample code will help!)
danpost danpost

2017/10/8

#
First, get the MouseInfo object:
1
MouseInfo mi = Greenfoot.getMouseInfo();
Then, make sure one exists, using:
1
if (mi != null)
Next, get the button number from the existing object:
1
int buttonNumber = mi.getButton();
Finally, check for which button you wish:
1
if (butttonNumber == 3)
Venbha Venbha

2017/10/9

#
Then it will look like this, right? (I will apply this one and see.)
1
2
3
4
5
6
7
8
9
MouseInfo mi = Greenfoot.getMouseInfo();
if (mi != null)
{
    int buttonNumber = mi.getButton();
    if (butttonNumber == 3)
    {
        //whatever I want it to do
    }
}
You need to login to post a reply.