VK code for Enter

when i try the codeRobot r = new Robot(); r.keyPress(20); r.keyRelease(20);it works for all the VK values i found except for 20 for return, i jus get Invalid key code Eception. can any one tell me the integer code for enter?thanks
[272 byte] By [boozelclarka] at [2007-11-27 4:07:06]
# 1
http://java.sun.com/javase/6/docs/api/java/awt/event/KeyEvent.html#VK_ENTERNote that it is generally better (more readable and robust) to use the predefined constants when doing operations. e.g. something like.....r.keyPress( KeyEvent.VK_ENTER
AndrewThompson64a at 2007-7-12 9:12:17 > top of Java-index,Security,Cryptography...
# 2
i tried that but it doesn't seem to work. but i figured it out so it's ok. thanks.
boozelclarka at 2007-7-12 9:12:17 > top of Java-index,Security,Cryptography...
# 3

> i tried that but it doesn't seem to work. ...

Here is a little example I made.

Does it work as you expect?import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

/** Example of using the Robot to type in a text field,

use the enter key, and activate a button via the space bar. */

class ActivateButtonUsingRobot {

static Robot robot;

static void activateKey(int keycode) {

robot.keyPress( keycode );

robot.keyRelease( keycode );

robot.delay( 150 );

}

public static void main(String[] args)

throws AWTException {

// if headless, exit early

robot = new Robot();

final JFrame f = new JFrame();

f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

JTextArea ta = new JTextArea("1st line!",10,20);

f.getContentPane().add(ta, BorderLayout.CENTER);

JButton button = new JButton("Press Me!");

button.addActionListener( new ActionListener() {

public void actionPerformed( ActionEvent ae ) {

JOptionPane.showMessageDialog(

f, "Button Activated!" );

}

} );

f.getContentPane().add(button, BorderLayout.SOUTH);

f.pack();

// put frame in center of screen

f.setLocationRelativeTo(null);

f.setVisible(true);

Dimension screensize =

Toolkit.getDefaultToolkit().getScreenSize();

// move mouse to center of screen, and ..

robot.mouseMove(

screensize.width/2, screensize.height/2 );

// ..activate the frame

robot.mousePress( InputEvent.BUTTON1_MASK );

robot.mouseRelease( InputEvent.BUTTON1_MASK );

robot.delay( 400 );

// try using enter key..

activateKey( KeyEvent.VK_ENTER );

activateKey( KeyEvent.VK_ENTER );

// this text should have a blank line above it..

activateKey( KeyEvent.VK_H );

activateKey( KeyEvent.VK_I );

// move to the button

robot.keyPress( KeyEvent.VK_CONTROL );

robot.keyPress( KeyEvent.VK_TAB );

robot.keyRelease( KeyEvent.VK_TAB );

robot.keyRelease( KeyEvent.VK_CONTROL );

robot.delay( 500 );

// try activating the button..

activateKey( KeyEvent.VK_SPACE );

}

}

AndrewThompson64a at 2007-7-12 9:12:17 > top of Java-index,Security,Cryptography...