open a notepad and send keystrokes and mouse events to it

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

open a notepad and send keystrokes and mouse events to it

sukhjeetb
can someone help me run a program, for notepad to open by itself without any manual input and automatically be filled with keystrokes without user input.
Reply | Threaded
Open this post in threaded view
|

Re: open a notepad and send keystrokes and mouse events to it

Gurmeet
I think you can use Java.awt.Robot class from the java libarary. You can create an object of Robot class and use the functions keyPress, keyRelease ,mouseMove, mousePress,mouserelease to do the things.
You have to use Runtime.getRuntime to open the notepad programatically

For example:

/* Opens the notepad */
Runtime.getRuntime().exec("notepad")

/*Create object of Robot class */
robot =Robot()

/*Insert a delay of 1 ms*/
robot.delay(100)

/*to maximise the notepad */

robot.keyPress(KeyEvent.VK_SHIFT)
robot.keyPress(KeyEvent.VK_ALT)
robot.keyPress(KeyEvent.VK_SPACE)
robot.keyPress(KeyEvent.VK_X)
robot.keyRelease(KeyEvent.VK_SHIFT)
robot.keyRelease(KeyEvent.VK_ALT)
robot.keyRelease(KeyEvent.VK_SPACE)
robot.keyRelease(KeyEvent.VK_X)

/*Write in notepad */
      robot.keyPress(KeyEvent.VK_H)
      robot.delay(500)
      robot.keyPress(KeyEvent.VK_E)
      robot.delay(500)
      robot.keyPress(KeyEvent.VK_L)
      robot.delay(500)
      robot.keyPress(KeyEvent.VK_L)
      robot.delay(500)
      robot.keyPress(KeyEvent.VK_O)
      robot.delay(500)


/*Moves the mouse pointer to close the notepad*/
robot.mouseMove(1005,10)
robot.mousePress(InputEvent.BUTTON1_MASK)
robot.delay(2000)
robot.mouseRelease(InputEvent.BUTTON1_MASK);