简体   繁体   中英

How to make java robot class type apostrophe '

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM