Hallo,
ich habe einen global KeyListener und auf Tastendruck starten mein Robot. Ich schaffe es nur nicht das dieser jetzt, nachdem ich die Taste los gelassen haben, sich beendet. Hilfe ;(
ich habe einen global KeyListener und auf Tastendruck starten mein Robot. Ich schaffe es nur nicht das dieser jetzt, nachdem ich die Taste los gelassen haben, sich beendet. Hilfe ;(
Java:
public void keyRobot() throws AWTException, InterruptedException {
Robot r = new Robot();
while (keyPressed
&& (click1 || click2 || click3 || click4 || clickml || clickmr)) {
if (click1) {
double rnd = (double) ((Math.random()) * 105 + 80);
r.keyPress(KeyEvent.VK_1);
r.keyRelease(KeyEvent.VK_1);
Thread.sleep((long) rnd);
}
if (click2) {
double rnd = (double) ((Math.random()) * 105 + 80);
r.keyPress(KeyEvent.VK_2);
r.keyRelease(KeyEvent.VK_2);
Thread.sleep((long) rnd);
}
if (click3) {
double rnd = (double) ((Math.random()) * 105 + 80);
r.keyPress(KeyEvent.VK_3);
r.keyRelease(KeyEvent.VK_3);
Thread.sleep((long) rnd);
}
if (click4) {
double rnd = (double) ((Math.random()) * 105 + 80);
r.keyPress(KeyEvent.VK_4);
r.keyRelease(KeyEvent.VK_4);
Thread.sleep((long) rnd);
}
if (clickml) {
double rnd = (double) ((Math.random()) * 105 + 80);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
Thread.sleep((long) rnd);
}
if (clickmr) {
double rnd = (double) ((Math.random()) * 105 + 80);
r.mousePress(InputEvent.BUTTON2_MASK);
r.mouseRelease(InputEvent.BUTTON2_MASK);
Thread.sleep((long) rnd);
}
}
}
Java:
public void nativeKeyPressed(NativeKeyEvent e) {
keyPressed = true;
try {
keyRobot();
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}