package cn.com.jautoitx;

import java.io.File;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.WinDef.POINT;
import com.sun.jna.platform.win32.WinDef.RECT;

/**
 * 
 * 
 * @author zhengbo.wang
 */
public class AutoItX {
	public static void main(String[] args) {
		File libFile = new File("lib/AutoItX3.dll");
		System.load(libFile.getAbsolutePath());
		AutoItXLibrary autoItX = (AutoItXLibrary) Native.loadLibrary(libFile.getName(), AutoItXLibrary.class);

		RECT rect = new RECT();
		rect.left = 0;
		rect.top = 0;
		rect.right = 100;
		rect.bottom = 100;

		POINT point = new POINT();

		autoItX.AU3_PixelSearch(rect, 0xFFFFFF, 0, 1, point);
		System.out.println("point.x = " + point.x + ", point.y = " + point.y);
	}

	protected static interface AutoItXLibrary extends Library {
		/**
		 * Searches a rectangle of pixels for the pixel color provided.
		 * 
		 * @param rect
		 *            position and size of rectangle.
		 * @param color
		 *            Colour value of pixel to find (in decimal or hex).
		 * @param shadeVariation
		 *            A number between 0 and 255 to indicate the allowed number
		 *            of shades of variation of the red, green, and blue
		 *            components of the colour. Default is 0 (exact match).
		 * @param step
		 *            Instead of searching each pixel use a value larger than 1
		 *            to skip pixels (for speed). E.g. A value of 2 will only
		 *            check every other pixel. Default is 1.
		 * @param point
		 *            Return the pixel's coordinates if success, sets
		 *            oAutoIt.error to 1 if color is not found.
		 */
		public void AU3_PixelSearch(RECT rect, int color, Integer shadeVariation, Integer step, POINT point);
	}
}
