Pregunta

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

¿Fue útil?

Solución

    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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top