Question

I am having problems making the method keyPress from the java robot class press the apostrophe key.

I am looking for something like:

Robot robot = new Robot(); 
robot.keyPress(KeyEvent.VK_APOSTROPHE);

Thanks.

Was it helpful?

Solution

Java doesn't have KeyEvent.VK_APOSTROPHE

Try:

robot.keyPress(KeyEvent.VK_QUOTE);  

or

robot.keyPress(KeyEvent.VK_BACKQUOTE); 

if you want the key above <Tab>

Edit: The above applies to java up to Java SE 8.

From Java 9 it appears the KeyEvent.VK_### fields are no longer the way to access keystrokes. Based on this answer to a related question something like this may be the new way:

FXRobot robot = FXRobotFactory.createRobot(scene);
robot.keyPress(KeyCode.QUOTE);
// or robot.keyPress(KeyCode.BACK_QUOTE);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top