|
||
|
||||
|
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 syntax highlighted code tags around your code: [highlight=Java] code here [/highlight] 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 |
| Beginners Eclipse Tutorial. How to run your first Eclipse Java Application. | JavaPF | Java Code Snippets and Tutorials | 6 | 26-08-2010 06:30 PM |
| How to Add a JMenu toolbar to a Java Swing application | JavaPF | Java Code Snippets and Tutorials | 3 | 30-04-2010 02:00 PM |
| [SOLVED] JAVA Calling Class | tazjaime | What's Wrong With My Code? | 4 | 23-04-2009 02:31 PM |
| How to Control your computers mouse using the Robot Class | JavaPF | Java Code Snippets and Tutorials | 3 | 11-02-2009 08:17 PM |
| How to Sort an Array using the java.util.Arrays class | JavaPF | Java Code Snippets and Tutorials | 0 | 01-12-2008 01:02 PM |
|
100 most searched terms
Search Cloud
|
| 2d arraylist java actionlistener actionlistener in java actionlistener java addactionlistener addactionlistener in java addactionlistener java applications of oops could not create java virtual machine xp double format java double to int 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.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java java 2d arraylist java actionlistener java addactionlistener java convert list to map java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming help java sendkeys java two dimensional arraylist java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics two dimensional arraylist java writing ipod apps |