2

I have Java code. I wrote it using Processing IDE, then used export application to get an .exe from this code.

Now I added this .exe to the Task Scheduler to run it in special time. The problem is: the Task Scheduler cannot run this .exe. When I try run this .exe by double clicking it, it works. But when I add it to the Task Scheduler, the task scheduler can not run it. I am using windows 10 / 64.

My code is:

import processing.serial.*; 
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
Serial s;
int sentences[]={
  KeyEvent.VK_W, KeyEvent.VK_E, KeyEvent.VK_L, KeyEvent.VK_C, KeyEvent.VK_O, KeyEvent.VK_M, KeyEvent.VK_E   
}; 

void setup() { 
  s=new Serial(this, "com3", 9600);
  size(1200, 500);
} 
int y=0;
void draw() {  
  String x=" ";
  int zz=0;
  if (s.available()>0) {  

    x= s.readString();  
    println(x);
    zz=1;
  }

  if (zz==1) {

    try {
      Robot robot =new Robot();
      robot.delay(1500);
      robot.keyPress(KeyEvent.VK_ENTER);
      robot.delay(5);
      robot.keyRelease(KeyEvent.VK_ENTER);
      robot.delay(1500);
      robot.mouseMove(555, 460);  
      robot.delay(1500);
      robot.mouseMove(300, 560);  
      robot.delay(1500);
      robot.mouseMove(240, 150);  
      //    robot.mousePress(MouseEvent.BUTTON1_MASK);
      //  robot.mouseRelease(MouseEvent.BUTTON1_MASK);
      //   robot.delay(3000);
      //  robot.keyPress(KeyEvent.VK_TAB);
      //  robot.delay(100);


      for (int i=0; i<sentences.length; i++) {
        robot.keyPress(sentences[i]); 
        robot.delay(2);
        robot.keyRelease(sentences[i]);
        robot.delay(50);
      }
      robot.delay(1500);
      robot.keyPress(KeyEvent.VK_ENTER);
      robot.delay(5);
      robot.keyRelease(KeyEvent.VK_ENTER);
    }
    catch(Exception e) {
      exit();
    }
    zz=0;
  }
}

I wonder if there is a special code I should write so the Task Scheduler can easily run it or any idea where is the problem?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Hasan_Naser
  • 204
  • 3
  • 13

0 Answers0