A virus is a program that does something unusual.
Unusual can be anything like
- snatching away the mouse control from you
- deleting files from your system,etc
Today we will see how can we create a java Application that blinks your capslock,moves your mouse on the screen automatically and fills your formpage on its own.I would rather call this Program a Java Robot.But this concept can be used in anyarea
Assume that you have an agency that books tickets frequently everyday.Instead of doing it manually,why not,pass all the details in properties files or xml files,and let your java robot do it for you.Doesn’t it sounds good?
I know you are eager to see that application.Even I am more eager to write the same…
RobotDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
public class RobotDemo implements ActionListener { | |
JFrame fr; | |
JLabel lb1; | |
JLabel lb2; | |
JTextField tf1; | |
JTextField tf2; | |
JButton btn1; | |
public RobotDemo() throws AWTException { | |
fr = new JFrame(); | |
lb1 = new JLabel("userName"); | |
lb2 = new JLabel("Password"); | |
tf1 = new JTextField(10); | |
tf2 = new JTextField(10); | |
btn1 = new JButton("Login"); | |
btn1.addActionListener(this); | |
fr.add(lb1); | |
fr.add(tf1); | |
fr.add(lb2); | |
fr.add(tf2); | |
fr.add(btn1); | |
fr.setLayout(new FlowLayout()); | |
fr.setVisible(true); | |
fr.setSize(200, 400); | |
fr.setResizable(false); | |
fr.setLocation(200, 300); | |
Robot rob = new Robot(); //throws AWTException | |
//Moves the cursor from 10,10 to 350,350 | |
for (int i = 1; i < 35; i++) { | |
rob.mouseMove(i * 10, i * 10); | |
try { | |
Thread.sleep(50); | |
} catch (Exception e) {} | |
} | |
for (int i = 1; i < 10; i++) { | |
rob.keyPress(KeyEvent.VK_CAPS_LOCK); | |
try { | |
Thread.sleep(500); | |
} catch (Exception e) {} | |
rob.keyRelease(KeyEvent.VK_CAPS_LOCK); | |
} | |
int keyCodes[] = new int[] { | |
KeyEvent.VK_S, KeyEvent.VK_A, KeyEvent.VK_T, KeyEvent.VK_Y, KeyEvent.VK_A | |
}; | |
int key; | |
for (int i = 0; i < keyCodes.length; i++) { | |
key = keyCodes[i]; | |
rob.keyPress(key); | |
rob.keyRelease(key); | |
try { | |
Thread.sleep(500); | |
} catch (Exception e) {} | |
} | |
for (int i = 35; i < 38; i++) { | |
rob.mouseMove(i * 10, i * 10); | |
try { | |
Thread.sleep(50); | |
} catch (Exception e) {} | |
} | |
//clicks mouse left button,so that we can get focus in pwd textfield | |
rob.mousePress(InputEvent.BUTTON1_MASK); | |
rob.mouseRelease(InputEvent.BUTTON1_MASK); | |
keyCodes = new int[] { | |
KeyEvent.VK_T, KeyEvent.VK_E, KeyEvent.VK_C, KeyEvent.VK_H | |
}; | |
for (int key1: keyCodes) { | |
rob.keyPress(key1); | |
rob.keyRelease(key1); | |
try { | |
Thread.sleep(500); | |
} catch (Exception e) {} | |
} | |
rob.mouseMove(300, 400); | |
rob.mousePress(InputEvent.BUTTON1_MASK); | |
rob.mouseRelease(InputEvent.BUTTON1_MASK); | |
} | |
public static void main(String[] args) throws AWTException { | |
new RobotDemo(); | |
} | |
public void actionPerformed(ActionEvent arg0) { | |
JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE); | |
} | |
} |
After creating the Application,you can convert it to .exe file and then use it in your own way.
Limitation:-
It can work only in computer where java is installed.
Hopefully you liked this Application.Does it deserve a like?
Thank you
No comments:
Post a Comment