I am quite new to Java and wanted to write a program that took keyboard inputs on my computer and turned them into exact mouse coordinates and then clicks. After researching for a while, I found the best way to do this was via the KeyListener interface to handle looking for the button presses and then an object of the Robot class to handle moving the mouse and clicking. After some basic tests using a few tutorials online that use JFrame, I tried to first create my Robot object to move the mouse, and then tell KeyTyped to call the mouseMove method each time q and a were pressed, but upon running the program, I only get errors saying that control cannot be resolved. What am I missing here?
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
public class Main implements KeyListener{
public static void main(String[] args) throws AWTException{
Robot control = new Robot();
}
@Override
public void keyTyped(KeyEvent e) {
switch(e.getKeyChar()) {
case 'q': control.mouseMove(20, 20);
break;
case 'a': control.mouseMove(60, 60);
break;
}
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
}