public class IDontLikeMouse { static MouseRecord rec = new MouseRecord(); // 座標の場所を記録する static MouseRepeat rep = new MouseRepeat(); // 記録された座標をもとにマウスを動かす
class MouseRecord { static List<String> mp = new ArrayList<String>(); static int posX, posY;
public static void getMousePosition() { PointerInfo pI = MouseInfo.getPointerInfo(); Point point = pI.getLocation(); posX = (int)point.getX(); posY = (int)point.getY(); try{ mp.add( posX + "," + posY ); // System.out.println(point.getX() + " " + point.getY()); System.out.printf( "[%4d,%4d]\n", posX, posY ); } catch( OutOfMemoryError e ) { System.out.println( e ); } }
public static void writeMousePosition() { try { File f = new File( "/Users/Naguchi/Desktop/pos.txt" ); PrintWriter pw = new PrintWriter( new BufferedWriter( new FileWriter( f ) ) ) ; Iterator it = mp.iterator(); while( it.hasNext() ) { pw.println( it.next () ); } pw.close(); } catch( IOException e ) { System.out.println( e ); } }
public static void threadSleep( int sleepTime ) { try { Thread.sleep( sleepTime ); } catch( InterruptedException e ) { System.out.println( "IdontStop!" ); } } }
class MouseRepeat {
public static void readMousePosition() { try { FileReader fr = new FileReader( "pos.txt" ); BufferedReader br = new BufferedReader( fr ); String mp; while( (mp = br.readLine()) != null ) { StringTokenizer st = new StringTokenizer( mp, "," ); while( st.hasMoreTokens() ) { int posX = Integer.parseInt( st.nextToken() ); int posY = Integer.parseInt( st.nextToken() ); // System.out.print( st.nextToken() + "," + st.nextToken() ); moveMousePosition( posX, posY ); threadSleep( 10 ); } } br.close(); } catch( Exception e ) { System.out.println( e ); } }
public static void moveMousePosition( int x, int y ) { try { Robot robot = new Robot(); robot.mouseMove( x, y );; } catch( AWTException e ) { e.printStackTrace(); } }
public static void threadSleep( int sleepTime ) { try { Thread.sleep( sleepTime ); } catch( InterruptedException e ) { System.out.println( "IdontStop!" ); } }