0

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

eltabo
  • 3,749
  • 1
  • 21
  • 33
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
  • For better help sooner, post your code as an [SSCCE](http://www.sscce.org) that demonstrates your problem. This allows users to copy/paste and reproduce your issue. – Duncan Jones Oct 11 '13 at 09:40

1 Answers1

2
    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.