깡패파서기

깡패파서기

 

package p1;

import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.io.File;

import javax.swing.JEditorPane;
import javax.swing.JFileChooser;

import org.apache.catalina.ant.FindLeaksTask;

import com.sun.java.swing.plaf.windows.resources.windows;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;

public class Main {
 static Robot robot;
 public static void main(String[] args) {
  
  ProcessBuilder p=new ProcessBuilder(“notepad.exe”);
  WinDef.HWND hWnd;//윈도우 핸들
  try{
   //로봇 선언
   robot=new Robot();
   
   
   for(int i=1;i<=100;i++){
   //기존의 파일이 있다면 미리 지운다
   File f=new File(“c:\\data\\g”+i+”.txt”);
   if(f.exists()){System.out.println(“기존 파일을 삭제”);f.delete();}
   
   hWnd = User32.INSTANCE.FindWindow(“Notepad”, null);//메모장이 없으므로 널이 나와야 한다
   
   if(hWnd!=null){
    System.out.println(“실행 중인 메모장을 종료한 후 다시 시작해주세요”);
    return;
   }
   
   //메모장을 켠다
   p.start();
   
   //메모장이 켜졌는지 검사
   hWnd=null;
   while(hWnd==null){
    //System.out.println(“메모장을 로드 중입니다”);
    robot.delay(500);
    hWnd = User32.INSTANCE.FindWindow(“Notepad”, null);
   }
   
   //파일을 연다
   CtrlO(0);
   
   //열기 창이 켜졌는지 검사
   hWnd=null;
   while(hWnd==null){
    //System.out.println(“열기 창을 로드 중입니다”);
    robot.delay(500);
    hWnd = User32.INSTANCE.FindWindow(null, “열기”);
   }
   
   String target=”신촌”;
   String str=”https://www.google.co.kr/search?hl=ko&as_q=”+target+”&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=&as_occt=any&safe=images&as_filetype=&as_rights=&start=”+(i*10-10);
   
   Main m=new Main();
   m.setClipboardContents(str);

   //한땀한땀 입력::: //str=str.toLowerCase(); //keyPress(str);
   
   //url명을 붙여넣기 해서 엔터친다
   CtrlV(200);
   Enter();
   
   //열기 창이 닫혔는지 검사
   hWnd = User32.INSTANCE.FindWindow(null, “열기”);
   while(hWnd!=null){
    //System.out.println(“열기 창을 닫는 중입니다”);
    robot.delay(500);
    hWnd = User32.INSTANCE.FindWindow(null, “열기”);
   }
   robot.delay(100);
   
   //파일 저장 윈도우를 연다
   CtrlS(0);
   
   //저장 창이 켜졌는지 검사
   hWnd=null;
   while(hWnd==null){
    //System.out.println(“저장 창을 로드 중입니다”);
    robot.delay(500);
    hWnd = User32.INSTANCE.FindWindow(null, “다른 이름으로 저장”);
   }
   robot.delay(100);
   
   //저장한다
   m.setClipboardContents(“c:\\data\\g”+i+”.txt”);
   CtrlV(200);
   Enter();
   
   //저장 창이 닫혔는지 검사
   hWnd = User32.INSTANCE.FindWindow(null, “다른 이름으로 저장”);
   while(hWnd!=null){
    System.out.println(“저장 창을 닫는 중입니다”);
    robot.delay(500);
    hWnd = User32.INSTANCE.FindWindow(null, “다른 이름으로 저장”);
   }
   robot.delay(100);
   
   //메모장을 끈다
   AltF4(200);
   
   while(!f.exists()){
    //파일이 존재하지 않는다면 문제가 생긴 것이다
    System.out.println(“파일을 저장중”);
   }
   
   while(!f.canRead()){
    System.out.println(“대기”);
   }
   
   //메모장이 꺼졌는지 검사
   hWnd = User32.INSTANCE.FindWindow(“Notepad”, null);
   while(hWnd!=null){
    //System.out.println(“메모장을 닫는 중입니다”);
    robot.delay(500);
    hWnd = User32.INSTANCE.FindWindow(“Notepad”, null);
   }
   System.out.println(i+”번째 파일 : “+(i*10-10)+”번째부터 “+(i*10-1)+”까지 세이브됨”);
   
    }//포문 닫힘
  }
  catch(Exception ex){System.out.println(“에러”+ex.getMessage());}
  

 }
 public void setClipboardContents(String str){
  
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        StringSelection contents = new StringSelection(str);
        clipboard.setContents(contents, null);

   }

 public static void keyPress(String str) throws Exception{
    for(int i=0;i<str.length();i++){
    
     String mykey=str.substring(i,i+1);
     int newkey=mykey.charAt(0);
    
     if(mykey.equals(“:”)){
     Colon();
     }
     else if(mykey.equals(“/”)){
      Slash();
     }
     else if(mykey.equals(“.”)){
      Dot();
     }
     else if(mykey.equals(“?”)){
      System.out.println(“d”);
       Quest();
     }
     else if(mykey.equals(“&”)){
       Andmark();
     }
     else if(mykey.equals(“_”)){
       Underbar();
     }
     else if(mykey.equals(“=”)){
       Eqmark();
     }
     else if(mykey.equals(“%”)){
       Permark();
     }
     else if(mykey.equals(“1”)){
       num1();
     }
     else if(mykey.equals(“2”)){
       num2();
     }
     else if(mykey.equals(“3”)){
       num3();
     }
     else if(mykey.equals(“4”)){
       num4();
     }
     else if(mykey.equals(“5”)){
       num5();
     }
     else if(mykey.equals(“6”)){
       num6();
     }
     else if(mykey.equals(“7”)){
       num7();
     }
     else if(mykey.equals(“8”)){
       num8();
     }
     else if(mykey.equals(“9”)){
       num9();
     }
     else if(mykey.equals(“0”)){
       num0();
     }
     else{
      PressWhat(newkey);
     }
    
     robot.delay(200);
    }
    Enter();
 }
 
 //http://web.mit.edu/gleitz/gizmoball/trunk/api/src-html/gizmoball/SwingKeyboardInput.html
 public static void Quest() throws Exception{
//    robot.keyPress(63);
//    robot.keyRelease(63);
  robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_SLASH);
    robot.keyRelease(KeyEvent.VK_SLASH);
    robot.keyRelease(KeyEvent.VK_SHIFT);
 }
 public static void AltF4(int delay) throws Exception{
  robot.keyPress(KeyEvent.VK_ALT);
    robot.keyPress(KeyEvent.VK_F4);
    robot.keyRelease(KeyEvent.VK_F4);
    robot.keyRelease(KeyEvent.VK_ALT);
    robot.delay(delay);
 }
 public static void Andmark() throws Exception{
//    robot.keyPress(38);
//    robot.keyRelease(38);
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_7);
    robot.keyRelease(KeyEvent.VK_7);
    robot.keyRelease(KeyEvent.VK_SHIFT);
 }
 public static void Underbar() throws Exception{
//    robot.keyPress(95);
//    robot.keyRelease(95);
  robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(45);
    robot.keyRelease(45);
    robot.keyRelease(KeyEvent.VK_SHIFT);
 }
 public static void num1() throws Exception{robot.keyPress(KeyEvent.VK_1); robot.keyRelease(KeyEvent.VK_1);}
 public static void num2() throws Exception{robot.keyPress(KeyEvent.VK_2); robot.keyRelease(KeyEvent.VK_2);}
 public static void num3() throws Exception{robot.keyPress(KeyEvent.VK_3); robot.keyRelease(KeyEvent.VK_3);}
 public static void num4() throws Exception{robot.keyPress(KeyEvent.VK_4); robot.keyRelease(KeyEvent.VK_4);}
 public static void num5() throws Exception{robot.keyPress(KeyEvent.VK_5); robot.keyRelease(KeyEvent.VK_5);}
 public static void num6() throws Exception{robot.keyPress(KeyEvent.VK_6); robot.keyRelease(KeyEvent.VK_6);}
 public static void num7() throws Exception{robot.keyPress(KeyEvent.VK_7); robot.keyRelease(KeyEvent.VK_7);}
 public static void num8() throws Exception{robot.keyPress(KeyEvent.VK_8); robot.keyRelease(KeyEvent.VK_8);}
 public static void num9() throws Exception{robot.keyPress(KeyEvent.VK_9); robot.keyRelease(KeyEvent.VK_9);}
 public static void num0() throws Exception{robot.keyPress(KeyEvent.VK_0); robot.keyRelease(KeyEvent.VK_0);}
 
 public static void Permark() throws Exception{
  robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_5);
    robot.keyRelease(KeyEvent.VK_5);
    robot.keyRelease(KeyEvent.VK_SHIFT);
 }
 public static void Eqmark() throws Exception{
    robot.keyPress(61);
    robot.keyRelease(61);
 }
 public static void PressWhat(int nkey) throws Exception{
   robot.keyPress(nkey-32);
   robot.keyRelease(nkey-32);
  }
  public static void Enter() throws Exception{
   robot.keyPress(KeyEvent.VK_ENTER);
   robot.keyRelease(KeyEvent.VK_ENTER); //97을 넣으면 숫자1이 나옴
  }
  public static void Dot() throws Exception{
   robot.keyPress(46);
   robot.keyRelease(46);
  }
  public static void Slash() throws Exception{
   robot.keyPress(KeyEvent.VK_SLASH);
   robot.keyRelease(KeyEvent.VK_SLASH);
  }
  public static void CtrlO(int delay) throws Exception{
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_O);
    robot.keyRelease(KeyEvent.VK_O);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.delay(delay);
 }
  public static void CtrlY(int delay) throws Exception{
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_Y);
    robot.keyRelease(KeyEvent.VK_Y);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.delay(delay);
 }
  public static void CtrlW(int delay) throws Exception{
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_W);
    robot.keyRelease(KeyEvent.VK_W);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.delay(delay);
 }
 public static void CtrlS(int delay) throws Exception{
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_S);
    robot.keyRelease(KeyEvent.VK_S);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.delay(delay);
 }
 public static void CtrlV(int delay) throws Exception{
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.delay(delay);
 }
 public static void Colon() throws Exception{
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_SEMICOLON);
    robot.keyRelease(KeyEvent.VK_SEMICOLON);
    robot.keyRelease(KeyEvent.VK_SHIFT);
 }

}