You can do this easily with the Robot
class. It practically presses a button, without special targeting or anything else.
For example, to press Enter :
Robot r = new Robot(); r.keyPress(KeyEvent.VK_ENTER); r.keyRelease(KeyEvent.VK_ENTER);
source share