I am working on a simple speech recognition project. I have a command called scroll up where I want to use the class to press the UP key.
This is the code:
else if(resultText.equalsIgnoreCase("scroll up"))
{
try {
Robot robot = new Robot();
robot.delay(5000);
robot.keyPress(KeyEvent.VK_UP);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_UP);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_UP);
}
catch (AWTException e){
e.printStackTrace();
}
}
I have already imported these
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
Now the same code works well in another project, but not in the present project. What am I doing wrong?