[JAVA] mouse 제어

프로그래밍/JAVA 2022. 12. 1. 15:31 posted by 야매코더

java 마우스 제어

/******************************************
 
java version : 18.0.1.1
 
******************************************/

package automouse;

import java.awt.AWTException;
import java.awt.MouseInfo;
import java.awt.PointerInfo;
import java.awt.Robot;
import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;

public class AutoMouse {

	public static final int ONE_SECONDS = 1000;
	public static final int MAX_Y = 400;
	public static final int MAX_X = 400;

	public static void main(String[] args) {
		Robot robot;
		PointerInfo pt = MouseInfo.getPointerInfo();		
		try {
			robot = new Robot();
			while (true) {				
				 pt = MouseInfo.getPointerInfo();                 
				System.err.println("log time : " + getTime());
				robot.mouseMove(pt.getLocation().x, pt.getLocation().y +1);
				robot.mouseMove(pt.getLocation().x, pt.getLocation().y );
				Thread.sleep(ONE_SECONDS * 60);				
			}
		} catch (AWTException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	
	private static String getTime() {
        Date now = Calendar.getInstance().getTime();
        // 포맷팅 정의
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy년 MM월 dd일 HH시 mm분 ss초"); 
        // 포맷팅 적용
        String formatedNow = formatter.format(now);		
		
		return formatedNow;
	}
}

 

반응형