简体   繁体   中英

How to Type URL using Robot class in Java

I want to create program which can type automatically using following methods:

robot.keyPress(code);
robot.keyRelease(code);

but i can not press Any Special Characters, It throws Exception like:

Exception in thread "main" java.lang.IllegalArgumentException: Invalid key code
at sun.awt.windows.WRobotPeer.keyPress(Native Method)
at java.awt.Robot.keyPress(Unknown Source)
at mypkg.GooglePiano.type(GooglePiano.java:65)
at mypkg.GooglePiano.<init>(GooglePiano.java:45)
at mypkg.GooglePiano.main(GooglePiano.java:16)

I want to type : http://google.com/?q=pratik+butani but its print http only.

Please help me

    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_8);
    robot.keyRelease(KeyEvent.VK_8);        
    robot.keyRelease(KeyEvent.VK_SHIFT);

When you try to type '*' from keyboard, you pres shift+8. Same key storkes should be simulated. Similar way can be used for any special characters.

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