I made this program that spams space bar every 17 milliseconds and I am wanting it to only spam spacebar when I am holding space. Is there Any way I can do this? I tried watching some tutorials on it but could not figure it out. I am quite new to Java but I really just wanted to make this.
import java.awt.event.KeyEvent;
import javax.swing.*;
import java.awt.*;
public class skript {
public static void main(String[] args) {
boolean loop = true;
while(loop = true) {
try {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
try { Thread.sleep(17); }
catch (InterruptedException e) { e.printStackTrace(); }
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
}
catch (AWTException e) { e.printStackTrace(); }
}
}
}