Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Robot Exception

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Robot Exception

    Hi. I've made a program that automatically types for the user. The user types in what he/she wants the program to type, and the program just repeats typing over and over. Now this works fine with letters, but I can't get it to work with symbols. (e.g. Exclamation Mark, Parentheses)

    Can anyone tell me what's wrong? It may just be my computer. I'm running Windows 7 x64. Here's my code:

    	typer.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e){
    				int item = list1.getSelectedIndex();
    				try {
    					robot = new Robot();
    					String text = list1.getItem(item);
    					for(int i2 = 0; i2 < text.length(); i2++){
    						write(text.charAt(i2));
    					}
    				       robot.keyPress(KeyEvent.VK_ENTER);
     
    				   if(rdbtnTopToBottom.isSelected() == true){
     
    					if(item == list1.countItems() - 1){
    						list1.select(0);
    					}else{
    						list1.select(item + 1);
    					}
     
    				   }else if(rdbtnBottomToTop.isSelected() == true){
    				    	   if(item == 0){
    				    		   list1.select(list1.countItems() -1);
    				    	   }else{
    				    		   list1.select(item - 1);
    				    	   }
    				   }else if(rdbtnRandom.isSelected() == true){
    					   Random rnd = new Random();
    					  list1.select(rnd.nextInt(list1.countItems()));
    				   }
     
    				} catch (AWTException e1) {					// TODO Auto-generated catch block
    					e1.printStackTrace();
    				}	
    			}
    			});
     
    public  void write(char letter){
            switch (letter) {
            case 'a': robot.keyPress(KeyEvent.VK_A); break;
            case 'b': robot.keyPress(KeyEvent.VK_B); break;
            case 'c': robot.keyPress(KeyEvent.VK_C); break;
            case 'd': robot.keyPress(KeyEvent.VK_D); break;
            case 'e': robot.keyPress(KeyEvent.VK_E); break;
            case 'f': robot.keyPress(KeyEvent.VK_F); break;
            case 'g': robot.keyPress(KeyEvent.VK_G); break;
            case 'h': robot.keyPress(KeyEvent.VK_H); break;
            case 'i': robot.keyPress(KeyEvent.VK_I); break;
            case 'j': robot.keyPress(KeyEvent.VK_J); break;
            case 'k': robot.keyPress(KeyEvent.VK_K); break;
            case 'l': robot.keyPress(KeyEvent.VK_L); break;
            case 'm': robot.keyPress(KeyEvent.VK_M); break;
            case 'n': robot.keyPress(KeyEvent.VK_N); break;
            case 'o': robot.keyPress(KeyEvent.VK_O); break;
            case 'p': robot.keyPress(KeyEvent.VK_P); break;
            case 'q': robot.keyPress(KeyEvent.VK_Q); break;
            case 'r': robot.keyPress(KeyEvent.VK_R); break;
            case 's': robot.keyPress(KeyEvent.VK_S); break;
            case 't': robot.keyPress(KeyEvent.VK_T); break;
            case 'u': robot.keyPress(KeyEvent.VK_U); break;
            case 'v': robot.keyPress(KeyEvent.VK_V); break;
            case 'w': robot.keyPress(KeyEvent.VK_W); break;
            case 'x': robot.keyPress(KeyEvent.VK_X); break;
            case 'y': robot.keyPress(KeyEvent.VK_Y); break;
            case 'z': robot.keyPress(KeyEvent.VK_Z); break;
            case 'A': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'B': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_B); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'C': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_C); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'D': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_D); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'E': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_E); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'F': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_F); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'G': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_G); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'H': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_H); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'I': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_I); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'J': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_J); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'K': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_K); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'L': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_L); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'M': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_M); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'N': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_N); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'O': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_O); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'P': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_P); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'Q': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_Q); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'R': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_R); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'S': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_S); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'T': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_T); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'U': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_U); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'V': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'W': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_W); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'X': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_X); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'Y': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_Y); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'Z': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_Z); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '`': robot.keyPress(KeyEvent.VK_BACK_QUOTE); break;
            case '0': robot.keyPress(KeyEvent.VK_0); break;
            case '1': robot.keyPress(KeyEvent.VK_1); break;
            case '2': robot.keyPress(KeyEvent.VK_2); break;
            case '3': robot.keyPress(KeyEvent.VK_3); break;
            case '4': robot.keyPress(KeyEvent.VK_4); break;
            case '5': robot.keyPress(KeyEvent.VK_5); break;
            case '6': robot.keyPress(KeyEvent.VK_6); break;
            case '7': robot.keyPress(KeyEvent.VK_7); break;
            case '8': robot.keyPress(KeyEvent.VK_8); break;
            case '9': robot.keyPress(KeyEvent.VK_9); break;
            case '-': robot.keyPress(KeyEvent.VK_MINUS); break;
            case '=': robot.keyPress(KeyEvent.VK_EQUALS); break;
            case '~': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_BACK_QUOTE); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '!': robot.keyPress(KeyEvent.VK_EXCLAMATION_MARK); break;
            case '@': robot.keyPress(KeyEvent.VK_AT); break;
            case '#': robot.keyPress(KeyEvent.VK_EXCLAMATION_MARK); break;
            case '$': robot.keyPress(KeyEvent.VK_DOLLAR); break;
            case '%': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_5); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '^': robot.keyPress(KeyEvent.VK_CIRCUMFLEX); break;
            case '&': robot.keyPress(KeyEvent.VK_AMPERSAND); break;
            case '*': robot.keyPress(KeyEvent.VK_ASTERISK); break;
            case '(': robot.keyPress(KeyEvent.VK_LEFT_PARENTHESIS); break;
            case ')': robot.keyPress(KeyEvent.VK_RIGHT_PARENTHESIS); break;
            case '_': robot.keyPress(KeyEvent.VK_UNDERSCORE); break;
            case '+': robot.keyPress(KeyEvent.VK_PLUS); break;
            case '[': robot.keyPress(KeyEvent.VK_OPEN_BRACKET); break;
            case ']': robot.keyPress(KeyEvent.VK_CLOSE_BRACKET); break;
            case '\\': robot.keyPress(KeyEvent.VK_BACK_SLASH); break;
            case '{': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_OPEN_BRACKET); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '}': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_CLOSE_BRACKET); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '|': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_BACK_SLASH); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case ';': robot.keyPress(KeyEvent.VK_SEMICOLON); break;
            case ':': robot.keyPress(KeyEvent.VK_COLON); break;
            case '\'': robot.keyPress(KeyEvent.VK_QUOTE); break;
            case '"': robot.keyPress(KeyEvent.VK_QUOTEDBL); break;
            case ',': robot.keyPress(KeyEvent.VK_COMMA); break;
            case '<': robot.keyPress(KeyEvent.VK_LESS); break;
            case '.': robot.keyPress(KeyEvent.VK_PERIOD); break;
            case '>': robot.keyPress(KeyEvent.VK_GREATER); break;
            case '/': robot.keyPress(KeyEvent.VK_SLASH); break;
            case '?': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_SLASH); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case ' ': robot.keyPress(KeyEvent.VK_SPACE); break;
            }
    	}

    Here is the exception I get in Eclipse:


    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid key code
    at sun.awt.windows.WRobotPeer.keyPress(Native Method)
    at java.awt.Robot.keyPress(Unknown Source)
    at main.write(main.java:553)
    at main$12.actionPerformed(main.java:404)
    at javax.swing.Timer.fireActionPerformed(Unknown Source)
    at javax.swing.Timer$DoPostEvent.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)



    Thanks for any help!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Robot Exception

    Look at your code for '%'

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Robot Exception

    Yes, I couldn't find an event in KeyEvent for the parentheses, so the robot holds shift and presses 5 to write it. What about it, though?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Robot Exception

    What about it, though?
    I thought you wanted to print ( and ).

    Look at your keyboard. Where is the %? What did you have Robot do to print the %?
    Now look at the (. Where is it? Just 4 keys to the right of the %.
    Do the same with Robot for the ( as you did for the %

  5. The Following User Says Thank You to Norm For This Useful Post:

    Kanyon (September 14th, 2011)

  6. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Robot Exception

    Yes, I have tried this. I get the same error when typing the parentheses, or any other symbol for that matter, with the shift key being held.

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Robot Exception

    Strange, I am able to have Robot print the characters in this line with no problem:
    String text = "This is the word? ()!";

  8. #7
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Robot Exception

    Hmmm. I'll have to take a closer look at it.

  9. #8
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Robot Exception

    Oh, I'm sorry, you were right. I don't know where that exception came from, but it's gone now. Anyway, the problem is solved. I guess it can only type keys that don't require a modifier. Adding the shift key worked. I can now type any English letter/symbol. Thanks!

    If anyone wants it, here is the modified code:
    	public  void write(char letter){
            switch (letter) {
            case 'a': robot.keyPress(KeyEvent.VK_A); break;
            case 'b': robot.keyPress(KeyEvent.VK_B); break;
            case 'c': robot.keyPress(KeyEvent.VK_C); break;
            case 'd': robot.keyPress(KeyEvent.VK_D); break;
            case 'e': robot.keyPress(KeyEvent.VK_E); break;
            case 'f': robot.keyPress(KeyEvent.VK_F); break;
            case 'g': robot.keyPress(KeyEvent.VK_G); break;
            case 'h': robot.keyPress(KeyEvent.VK_H); break;
            case 'i': robot.keyPress(KeyEvent.VK_I); break;
            case 'j': robot.keyPress(KeyEvent.VK_J); break;
            case 'k': robot.keyPress(KeyEvent.VK_K); break;
            case 'l': robot.keyPress(KeyEvent.VK_L); break;
            case 'm': robot.keyPress(KeyEvent.VK_M); break;
            case 'n': robot.keyPress(KeyEvent.VK_N); break;
            case 'o': robot.keyPress(KeyEvent.VK_O); break;
            case 'p': robot.keyPress(KeyEvent.VK_P); break;
            case 'q': robot.keyPress(KeyEvent.VK_Q); break;
            case 'r': robot.keyPress(KeyEvent.VK_R); break;
            case 's': robot.keyPress(KeyEvent.VK_S); break;
            case 't': robot.keyPress(KeyEvent.VK_T); break;
            case 'u': robot.keyPress(KeyEvent.VK_U); break;
            case 'v': robot.keyPress(KeyEvent.VK_V); break;
            case 'w': robot.keyPress(KeyEvent.VK_W); break;
            case 'x': robot.keyPress(KeyEvent.VK_X); break;
            case 'y': robot.keyPress(KeyEvent.VK_Y); break;
            case 'z': robot.keyPress(KeyEvent.VK_Z); break;
            case 'A': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'B': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_B); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'C': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_C); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'D': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_D); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'E': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_E); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'F': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_F); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'G': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_G); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'H': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_H); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'I': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_I); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'J': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_J); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'K': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_K); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'L': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_L); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'M': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_M); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'N': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_N); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'O': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_O); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'P': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_P); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'Q': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_Q); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'R': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_R); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'S': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_S); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'T': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_T); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'U': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_U); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'V': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'W': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_W); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'X': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_X); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'Y': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_Y); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case 'Z': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_Z); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '`': robot.keyPress(KeyEvent.VK_BACK_QUOTE); break;
            case '0': robot.keyPress(KeyEvent.VK_0); break;
            case '1': robot.keyPress(KeyEvent.VK_1); break;
            case '2': robot.keyPress(KeyEvent.VK_2); break;
            case '3': robot.keyPress(KeyEvent.VK_3); break;
            case '4': robot.keyPress(KeyEvent.VK_4); break;
            case '5': robot.keyPress(KeyEvent.VK_5); break;
            case '6': robot.keyPress(KeyEvent.VK_6); break;
            case '7': robot.keyPress(KeyEvent.VK_7); break;
            case '8': robot.keyPress(KeyEvent.VK_8); break;
            case '9': robot.keyPress(KeyEvent.VK_9); break;
            case '-': robot.keyPress(KeyEvent.VK_MINUS); break;
            case '=': robot.keyPress(KeyEvent.VK_EQUALS); break;
            case '~': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_BACK_QUOTE); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '!': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_1); robot.keyRelease(KeyEvent.VK_SHIFT);; break;
            case '@': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_2); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '#': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_3); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '$': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_4); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '%': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_5); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '^': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_6); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '&': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_7); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '*': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_8); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '(': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_9); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case ')': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_0); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '_': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_MINUS); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '+': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_EQUALS); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '[': robot.keyPress(KeyEvent.VK_OPEN_BRACKET); break;
            case ']': robot.keyPress(KeyEvent.VK_CLOSE_BRACKET); break;
            case '\\': robot.keyPress(KeyEvent.VK_BACK_SLASH); break;
            case '{': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_OPEN_BRACKET); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '}': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_CLOSE_BRACKET); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '|': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_BACK_SLASH); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case ';': robot.keyPress(KeyEvent.VK_SEMICOLON); break;
     
            case ':': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_SEMICOLON); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '\'': robot.keyPress(KeyEvent.VK_QUOTE); break;
            case '"': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_QUOTE); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case ',': robot.keyPress(KeyEvent.VK_COMMA); break;
            case '<': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_COMMA); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '.': robot.keyPress(KeyEvent.VK_PERIOD); break;
            case '>': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_PERIOD); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case '/': robot.keyPress(KeyEvent.VK_SLASH); break;
            case '?': robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress( KeyEvent.VK_SLASH); robot.keyRelease(KeyEvent.VK_SHIFT); break;
            case ' ': robot.keyPress(KeyEvent.VK_SPACE); break;
            }
    	}

Similar Threads

  1. How to Sendkeys to an application in Java using the Robot Class
    By JavaPF in forum Java SE API Tutorials
    Replies: 6
    Last Post: August 4th, 2011, 12:13 AM
  2. Need Help for Robot class even on inactive window
    By jamsubzero in forum Java Theory & Questions
    Replies: 3
    Last Post: March 5th, 2011, 09:29 PM
  3. Robot help.
    By mlan in forum AWT / Java Swing
    Replies: 1
    Last Post: February 14th, 2010, 04:26 PM
  4. How to Sendkeys to an application in Java using the Robot Class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 4
    Last Post: October 24th, 2009, 11:40 PM
  5. Java program to contol computer mouse using the awt Robot and events
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 3
    Last Post: February 11th, 2009, 04:17 PM

Tags for this Thread