We have many programming languages, but I prefer Java to any other. It's because of its huge libraries. Thanks to James Gosling.Oh..,I revealed..!!!Yea..it's through Java..
Know How...!!!
1. Open your Java IDE or cmd or whatever you are using to execute Java programs.
2. Copy the following code and paste it in your IDE. Make sure class name and program name matches.
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
class Notepad {
public static void main(String args[]) throws IOException, InterruptedException, AWTException{
Runtime.getRuntime().exec("notepad.exe");
Thread.sleep(2000);
Robot r=new Robot();
r.keyPress(KeyEvent.VK_T);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_H);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_I);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_S);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_SPACE);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_I);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_S);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_SPACE);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_F);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_U);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_N);
}
}
3. Run the program to view the result.
Okay...!You did this..But, why did this happen?Why did notepad open automatically and something is typed without, you physically typing?
The Runtime.getRuntime.exec() gives the power to Java to execute notepad directly. A starting delay of 2000 millisecs is introduced so that Notepad gets a chance to open and our program writes in Notepad and not anywhere else. After each letter, i introduced a delay of 500 millisecs so that it looks like someone is typing.
That's funny part of Java...!!! :) Let's learn many such techniques in upcoming articles...
No comments:
Post a Comment