0

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.

eltabo
  • 3,749
  • 1
  • 21
  • 33
Kiwi Bird
  • 145
  • 1
  • 2
  • 9

1 Answers1

2

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);
mcalex
  • 6,628
  • 5
  • 50
  • 80
  • Thanks for the qick reply! I know there is no VK_APOSTROPHY, it was just something in that format that I needed and this worked great! I can get back to my application now... – Kiwi Bird Jul 04 '13 at 22:09
  • This throws an IllegalArgumentException saying that the keycode is invalid – Conner Dassen Jul 02 '18 at 13:36
  • @mcalex, actually I prefer using regular robots. Most of the `KeyEvent.VK_###` fields work, for some reason the apostrophe key was called `VK_DEAD_ACUTE` (in my case at least) and in order to type a double quote I just had to press shift first. – Conner Dassen Jul 03 '18 at 15:30