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

2018/9/21

No Buttons Pressed

CosmicCaleb CosmicCaleb

2018/9/21

#
I want to make it so that when I am not pressing any buttons, a function happens. Here is what I have, but it doesn't work
public void act() 
    {
        if (Greenfoot.isKeyDown("any") == false)
        {
            moveDown();
        }
    }  
danpost danpost

2018/9/21

#
CosmicCaleb wrote...
I want to make it so that when I am not pressing any buttons, a function happens. Here is what I have, but it doesn't work << Code Omitted >>
The only way to check for "any" key down is to check each possible key individually. Maybe you can limit the number of keys that you want to check somehow. Without more information as to what you are actually wanting, it is difficult to give you advise on the best way to handle the issue.
Facehugger Facehugger

2018/9/23

#
Are you attempting to add an improvised gravity to your simulation? If so there are certainly better techniques for implementing such features.
CosmicCaleb CosmicCaleb

2018/9/24

#
if the left, right, up, and down keys are not pressed, then the function happens
danpost danpost

2018/9/24

#
CosmicCaleb wrote...
if the left, right, up, and down keys are not pressed, then the function happens
So, basically, you want something like this:
boolean up = Greenfoot.isKeyDown("up");
boolean down = Greenfoot.isKeyDown("down");
boolean left = Greenfoot.isKeyDown("left");
boolean right = Greenfoot.isKeyDown("right")
if (!up && !down && !left && !right)
{
    // perform function
}
CosmicCaleb CosmicCaleb

2018/9/25

#
Exactly! Thanks so much!!
You need to login to post a reply.