티스토리 뷰

package robot_bbs_insert;



import java.awt.Robot;

import java.awt.Toolkit;

import java.awt.datatransfer.Clipboard;

import java.awt.datatransfer.StringSelection;

import java.awt.event.KeyEvent;

import java.io.File;



/**

 * 클립보드에 있는것을 메모장에 붙여넣고 저장  

 */

public class Notepad {

	

	public static String DIR_NAME = "D:\\bet365\\";

	public static String FILE_NAME = "baseball.txt";

	

	public void fileDelete(String dest) {

		File file=new File(dest);

		if(file.exists()) {

			if(file.delete()) {

				System.out.println("파일삭제 성공");

			}else {

				System.out.println("파일삭제 실패");

			}

		}else {

			System.out.println("파일이 존재하지 않습니다");

		}

	}

	

	

	public void notepad() throws Exception {

		

		Runtime.getRuntime().exec("notepad");

		

		Thread.sleep(1000);

		

		Robot robot=new Robot();

		

		robot.keyPress(KeyEvent.VK_WINDOWS);

		robot.keyPress(KeyEvent.VK_UP);

		Thread.sleep(500);

		

		robot.keyRelease(KeyEvent.VK_WINDOWS);

		robot.keyRelease(KeyEvent.VK_UP);

		robot.delay(500);

		

		//붙여넣기

		robot.keyPress(KeyEvent.VK_CONTROL);

		robot.keyPress(KeyEvent.VK_V);

		robot.keyRelease(KeyEvent.VK_CONTROL);

		robot.keyRelease(KeyEvent.VK_V);

		robot.delay(200);

		

		//저장하기

		robot.keyPress(KeyEvent.VK_CONTROL);

		robot.keyPress(KeyEvent.VK_S);

		robot.keyRelease(KeyEvent.VK_CONTROL);

		robot.keyRelease(KeyEvent.VK_S);

		robot.delay(200);

		

		//파일명 클립보드에 복사

		StringSelection data=new StringSelection(DIR_NAME+FILE_NAME);

		Clipboard clipboard=Toolkit.getDefaultToolkit().getSystemClipboard();

		clipboard.setContents(data, data);

		

		Thread.sleep(1000);

		

		//붙여넣기

		robot.keyPress(KeyEvent.VK_CONTROL);

		robot.keyPress(KeyEvent.VK_V);

		robot.keyRelease(KeyEvent.VK_CONTROL);

		robot.keyRelease(KeyEvent.VK_V);

		robot.delay(200);

		

		//저장버튼 클릭

		robot.keyPress(KeyEvent.VK_ALT);

		robot.keyPress(KeyEvent.VK_S);

		robot.keyRelease(KeyEvent.VK_ALT);

		robot.keyRelease(KeyEvent.VK_S);

		robot.delay(200);

		

		//열려있는 노트패드 닫기

		robot.keyPress(KeyEvent.VK_ALT);

		robot.keyPress(KeyEvent.VK_F4);

		robot.keyRelease(KeyEvent.VK_ALT);

		robot.keyRelease(KeyEvent.VK_F4);

		robot.delay(200);

		

	}

	

	public static void main(String[] args){

		System.out.println("시작");

		try {

			Notepad dev=new Notepad();

			//파싱 전 파일 지워줘야 덮어쓸거냐고 안물어봄.

			dev.fileDelete(DIR_NAME+FILE_NAME);

			dev.notepad();

			

		}catch(Exception e) {

			e.printStackTrace();

		}

		System.out.println("끝");

	}



}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함