views:

158

answers:

2

Hi

is there anyway to type into a notepad.exe process from a JAVA process?

A: 

I don't have much experience with it but I think you'll want to check out the java Robot class

Graphics Noob
+2  A: 

Yes, using the robot is the solution:

import java.awt.Robot;
import java.awt.event.KeyEvent;

public class Notepad {

    static int keyInput[] = { KeyEvent.VK_J, KeyEvent.VK_A, KeyEvent.VK_V,
            KeyEvent.VK_A, KeyEvent.VK_SPACE };

    public static void main(String[] args) throws Exception {

        Runtime.getRuntime().exec("notepad");

        Robot robot = new Robot();
        for (int i = 0; i < keyInput.length; i++) {
            robot.keyPress(keyInput[i]);
            robot.delay(100);
        }
    }
}

if you want to convert a String to keyEvents check this question http://stackoverflow.com/questions/1248510/convert-string-to-keyevents

Dominique