Does anyone know how to make it so that a program written in Java can type into other programs (i.e. Microsoft Word, notepad, etc) when a button is pressed?
Java Programming
-
-
Java's probably the wrong language to use because it was historically huge on the "Sandbox" principle (no matter how noxious the programme, it shouldn't be able to affect the outside system).
You might look into a system call interface and emulate keystrokes.
-
I'm not quite sure what you mean by that. Do you want the java program to just edit the files? Or do you want it to directly interact with the other programs? Can you elaborate on what you want to do?
The latter is hard to do, you can use the robot class to emulate keystrokes:
import java.awt.*; import java.awt.event.*; import java.awt.AWTException; public class Robohobo { public static void main(String[] args)throws AWTException{ try { Robot hobo = new Robot(); Runtime.getRuntime().exec("notepad"); //opens notepad hobo.delay(3000); //3 second delay hobo.keyPress(KeyEvent.VK_A); //write stuff hobo.keyPress(KeyEvent.VK_B); hobo.keyPress(KeyEvent.VK_C); } catch (AWTException err) { System.out.println("Dammmmm youuuuuu"); } } }
-
Ah, yes, the second one is what I was talking about. Thank you !
-
np, here are the robot's functions: http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html