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

2021/1/13

mouseClicked(null) doesn't work at all but mouseMoved(null) does

M1S0 M1S0

2021/1/13

#
so what i'm trying to acomplish is to find out where the mouse is clicking, to do that i'm defining the mouse everytime it moves and i'm trying to find in which x,y it clicked, for some reason mouseClicked(null) does not trigger at all, i've tried spam clicking everywhere and i've even used an autoclicker to spam it a 100 cps this is the strip of code
public void act() {
        if(Greenfoot.mouseMoved(null)) {
        	MouseInfo Mouse = Greenfoot.getMouseInfo();
        	//System.out.println(Mouse); //this works
            if(Greenfoot.mouseClicked(null)) {
                System.out.println(Mouse.getX() + " | "+ Mouse.getY()); //this never prints
            }
        }
}
danpost danpost

2021/1/13

#
M1S0 wrote...
so what i'm trying to acomplish is to find out where the mouse is clicking, to do that i'm defining the mouse everytime it moves and i'm trying to find in which x,y it clicked, for some reason mouseClicked(null) does not trigger at all, i've tried spam clicking everywhere and i've even used an autoclicker to spam it a 100 cps this is the strip of code << Code Omitted >>
Your code requires that the mouse must be moving when the click occurs. Moving is not a necessary thing for a mouse click. Clicking is the only requirement here:
if (Greenfoot.mouseClicked(null))
{
    MouseInfo mouse = Greenfoot.getMouseInfo();
    System.out.println(mouse.getX() + " | "+ mouse.getY());
}
You need to login to post a reply.