Hi,
wollte wissen ob man die folgende For-Schleife mit einem einfachen Tastendruck auf ESC beenden kann. Kann auch das Programm komplett ausgeschaltet werden.
Wenn es geht freue ich mich gerne über einen Lösungsvorschlag.
Hätte man bestimmt auch ein bischen einfacher machne können, aber es funktioniert.
wollte wissen ob man die folgende For-Schleife mit einem einfachen Tastendruck auf ESC beenden kann. Kann auch das Programm komplett ausgeschaltet werden.
Wenn es geht freue ich mich gerne über einen Lösungsvorschlag.
Java:
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Bla {
public static void main(String[] args) throws AWTException {
final Robot robot = new Robot();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
for (int a = 0; a < 10; a++) {
for (int b = 0; b < 10; b++) {
for (int c = 0; c < 10; c++) {
if (i == 0) {
robot.keyPress(48);
robot.keyRelease(48);
}
if (i == 1) {
robot.keyPress(49);
robot.keyRelease(49);
}
if (i == 2) {
robot.keyPress(50);
robot.keyRelease(50);
}
if (i == 3) {
robot.keyPress(51);
robot.keyRelease(51);
}
if (i == 4) {
robot.keyPress(52);
robot.keyRelease(52);
}
if (i == 5) {
robot.keyPress(53);
robot.keyRelease(53);
}
if (i == 6) {
robot.keyPress(54);
robot.keyRelease(54);
}
if (i == 7) {
robot.keyPress(55);
robot.keyRelease(55);
}
if (i == 8) {
robot.keyPress(56);
robot.keyRelease(56);
}
if (i == 9) {
robot.keyPress(57);
robot.keyRelease(57);
}
if (a == 0) {
robot.keyPress(48);
robot.keyRelease(48);
}
if (a == 1) {
robot.keyPress(49);
robot.keyRelease(49);
}
if (a == 2) {
robot.keyPress(50);
robot.keyRelease(50);
}
if (a == 3) {
robot.keyPress(51);
robot.keyRelease(51);
}
if (a == 4) {
robot.keyPress(52);
robot.keyRelease(52);
}
if (a == 5) {
robot.keyPress(53);
robot.keyRelease(53);
}
if (a == 6) {
robot.keyPress(54);
robot.keyRelease(54);
}
if (a == 7) {
robot.keyPress(55);
robot.keyRelease(55);
}
if (a == 8) {
robot.keyPress(56);
robot.keyRelease(56);
}
if (a == 9) {
robot.keyPress(57);
robot.keyRelease(57);
}
if (b == 0) {
robot.keyPress(48);
robot.keyRelease(48);
}
if (b == 1) {
robot.keyPress(49);
robot.keyRelease(49);
}
if (b == 2) {
robot.keyPress(50);
robot.keyRelease(50);
}
if (b == 3) {
robot.keyPress(51);
robot.keyRelease(51);
}
if (b == 4) {
robot.keyPress(52);
robot.keyRelease(52);
}
if (b == 5) {
robot.keyPress(53);
robot.keyRelease(53);
}
if (b == 6) {
robot.keyPress(54);
robot.keyRelease(54);
}
if (b == 7) {
robot.keyPress(55);
robot.keyRelease(55);
}
if (b == 8) {
robot.keyPress(56);
robot.keyRelease(56);
}
if (b == 9) {
robot.keyPress(57);
robot.keyRelease(57);
}
if (c == 0) {
robot.keyPress(48);
robot.keyRelease(48);
}
if (c == 1) {
robot.keyPress(49);
robot.keyRelease(49);
}
if (c == 2) {
robot.keyPress(50);
robot.keyRelease(50);
}
if (c == 3) {
robot.keyPress(51);
robot.keyRelease(51);
}
if (c == 4) {
robot.keyPress(52);
robot.keyRelease(52);
}
if (c == 5) {
robot.keyPress(53);
robot.keyRelease(53);
}
if (c == 6) {
robot.keyPress(54);
robot.keyRelease(54);
}
if (c == 7) {
robot.keyPress(55);
robot.keyRelease(55);
}
if (c == 8) {
robot.keyPress(56);
robot.keyRelease(56);
}
if (c == 9) {
robot.keyPress(57);
robot.keyRelease(57);
}
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
try {
Thread.sleep(200);
} catch (InterruptedException ex) {
Logger.getLogger(Bla.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
}
},
5000);
}
}
Hätte man bestimmt auch ein bischen einfacher machne können, aber es funktioniert.