|
||
|
||||
|
For any of you that have used Visual Basic, you will probably know about SendKeys.
SendKeys is basically a way of sending keystrokes to an application. Java now has this ability thanks to the Robot Class. This code will show you how to send keystrokes to an application. In this case, Notepad.exe with a delay between each key. The Robot class can do a lot more so its worth looking into! Java Code
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
public class Robot1{
static int keyInput[] =
{
KeyEvent.VK_J, KeyEvent.VK_A, KeyEvent.VK_V, KeyEvent.VK_A, KeyEvent.VK_SPACE,
KeyEvent.VK_P, KeyEvent.VK_R, KeyEvent.VK_O, KeyEvent.VK_G, KeyEvent.VK_R,
KeyEvent.VK_A, KeyEvent.VK_M, KeyEvent.VK_M, KeyEvent.VK_I, KeyEvent.VK_N,
KeyEvent.VK_G, KeyEvent.VK_SPACE, KeyEvent.VK_F, KeyEvent.VK_O, KeyEvent.VK_R,
KeyEvent.VK_U, KeyEvent.VK_M, KeyEvent.VK_S, KeyEvent.VK_SPACE, KeyEvent.VK_PERIOD,
KeyEvent.VK_C, KeyEvent.VK_O, KeyEvent.VK_M
};
public static void main(String[] args) throws AWTException,IOException {
Runtime.getRuntime().exec("notepad");
Robot robot = new Robot();
for (int i = 0; i < keyInput.length; i++)
{
robot.keyPress(keyInput[i]);
robot.delay(100);
}
}
}
![]() Try it for yourself. Its cool...
__________________
Don't forget to add code tags around your code: ![]() Forum Tip: Add to peoples reputation ( ) by clicking the button on their useful posts.
|
| The Following 2 Users Say Thank You to JavaPF For This Useful Post: | ||
bocahTuaNakalzz (25-10-2009), JFujy (22-09-2009) | ||
|
|||
|
ei this is one is cool ,
anyway sir java , what other kind of executable file can i use with this method..? in a console output.. how should i code it? |
![]() |
| Tags |
| robot class, send keys |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to Add a JMenu toolbar to a Java Swing application | JavaPF | Java Code Snippets and Tutorials | 2 | 04-05-2009 02:56 PM |
| [SOLVED] JAVA Calling Class | tazjaime | What's Wrong With My Code? | 4 | 23-04-2009 02:31 PM |
| Beginners Eclipse Tutorial. How to run your first Eclipse Java Application. | JavaPF | Java Code Snippets and Tutorials | 3 | 12-03-2009 10:07 AM |
| How to Control your computers mouse using the Robot Class | JavaPF | Java Code Snippets and Tutorials | 3 | 11-02-2009 09:17 PM |
| How to Sort an Array using the java.util.Arrays class | JavaPF | Java Code Snippets and Tutorials | 0 | 01-12-2008 02:02 PM |
|
100 most searched terms
Search Cloud
|
| 2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java actionlistener java actionlistener jbutton addactionlistener addactionlistener java avatar hardware id convert double to integer java double format java double to int java double to integer in java double to integer java eclipse shortcut keys eclipse tutorial for beginners exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java hardware id avatar java 2 dimensional arraylist java 2d arraylist java actionlistener java addactionlistener java button actionlistener java convert double to int java double format java double to int java double to integer java for beginner eclippse java format double java forum java forums java get mouse position java ipod touch java jbutton java list to map java mouse position java programming forum java programming forums java sendkeys java.lang.reflect.invocationtargetexception java.util.arraylist jbutton actionlistener jbutton java programming forums string to int java two dimensional arraylist java writing apps for ipod touch |