My eclipse tells me that i need to use an static modifier but when i do so the hole thing becomes wrong. Here is my code I hope that you can help me and tell me what i did messed up(i got the hint for the inner class from StealthyHunter7):
public class ClickBot
{
private class Key
implements KeyListener
{
private boolean spacebarPressed = false;
@Override
public void keyTyped(KeyEvent e)
{
}
@Override
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_SPACE)
{
spacebarPressed = true;
}
}
@Override
public void keyReleased(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_SPACE)
{
spacebarPressed = false;
}
}
public boolean isSpacebarPressed()
{
return spacebarPressed;
}
}
Key keyObject = new Key();
public static void main(String[] args) throws IOException, AWTException
{
JFrame.addKeyListener(keyObject);
final Robot robot = new Robot();
robot.delay(2000);
while(keyObject.spacebarPressed())
{
{
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(30);
}
}
}
}