Wednesday 23 April 2014

Java : Robot : Write Data to Notepad


import java.awt.Robot;
import java.awt.event.KeyEvent;

public class WriteToNotepad{
 static Robot r;
 static int count = 0;
    
 static void processString(String str)throws Exception{   
  Thread.sleep(500);
  String str1 = str.toUpperCase();
  count = count + str.length();

  for(int i =0; i < str.length(); i++){
   int k = str1.charAt(i);
   if(i == 32){
    r.keyPress(KeyEvent.VK_SPACE);
   }
   else{   
    r.keyPress(k);         
    Thread.sleep(500);
   }
  }    
 }
   
 public static void main(String args[])throws Exception{
  r=new Robot();
  
  try{
  Runtime.getRuntime().exec("notepad.exe");
   processString("Welcome Java"); 
  }
  catch(Exception e){   
  }
 }
}

Output





                                                             Home

No comments:

Post a Comment