Pregunta

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.

¿Fue útil?

Solución

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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top