1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.util.GregorianCalendar;
/**
*
* @author poste_bruno
*/
public class Main {
public Main() {
}
public static void main(String[] args) {
// Lancement du tableur
// Attention, sous Windaube, remplacer les "\" par des "/" dans le chemin
try {
Process proc = Runtime.getRuntime().exec("C:/Program Files/OpenOffice.org 2.4/program/scalc.exe");
} catch (IOException e) {
e.printStackTrace();
}
// temporisation empirique pour attendre que l'application soit bien chargée avant de lancer le robot
Temporisation(2000);
// lancement du robot
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException ex) {
ex.printStackTrace();
}
robot.keyPress(KeyEvent.VK_DOWN);
Temporisation(500);
robot.keyPress(KeyEvent.VK_RIGHT);
Temporisation(500);
robot.keyPress(KeyEvent.VK_A); /** pression de la touche A */
robot.keyRelease(KeyEvent.VK_A); /** relachement de la touche A*/
}
// petit utilitaire de temporisation
private static void Temporisation(long NbMilliseconde) {
long M1, M2;
M1 = new GregorianCalendar().getTimeInMillis();
M2 = new GregorianCalendar().getTimeInMillis() + NbMilliseconde;
while (M1<M2) M1 = new GregorianCalendar().getTimeInMillis();
}
} |
Partager