Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.eaio.nativecall.IntCall;
- import com.eaio.nativecall.NativeCall;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.datatransfer.DataFlavor;
- import java.awt.datatransfer.Transferable;
- import java.awt.datatransfer.UnsupportedFlavorException;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class AutoHotkeyTest {
- public AutoHotkeyTest() {
- System.out.println("\nStarting...\n");
- control();
- setupSearch();
- }
- private static IntCall exec;
- public static int[] getWindowInfo(String windowName) {
- try {
- int x, y, width, height;
- ahk("WinGetPos, X, Y, Width, Height, " + windowName);
- ahk("Clipboard = %X%");
- x = Integer.parseInt(waitForClipboardChange(5).toString());
- ahk("Clipboard = %Y%");
- y = Integer.parseInt(waitForClipboardChange(5).toString());
- ahk("Clipboard = %Width%");
- width = Integer.parseInt(waitForClipboardChange(5).toString());
- ahk("Clipboard = %Height%");
- height = Integer.parseInt(waitForClipboardChange(5).toString());
- return new int[]{x, y, width, height};
- } catch (Throwable t) {
- return getWindowInfo(windowName);
- }
- }
- public static void setupSearch() {
- ahk("settitlematchmode 2\n" +
- "\n" +
- "CoordMode, ToolTip, screen\n" +
- "CoordMode, Mouse, screen\n" +
- "CoordMode, Pixel, screen");
- }
- public static int[] getCords() {
- ahk("Clipboard = %FoundX%\n");
- int x = Integer.parseInt(waitForClipboardChange(200).toString());
- ahk("Clipboard = %FoundY%\n");
- int y = Integer.parseInt(waitForClipboardChange(200).toString());
- return new int[]{x, y};
- }
- static Timer t = null;
- public static Object waitForClipboardChange(int miliSeconds) {
- try {
- t = new Timer(miliSeconds, new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- t = null;
- }
- });
- t.start();
- Object temp = null;
- while (temp == null && t != null) {
- temp = Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);
- }
- return temp;
- } catch (Throwable j) {
- j.printStackTrace();
- return 3;
- }
- }
- public static void clear() {
- Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new Transferable() {
- public DataFlavor[] getTransferDataFlavors() {
- return new DataFlavor[0];
- }
- public boolean isDataFlavorSupported(DataFlavor flavor) {
- return false;
- }
- public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
- return null;
- }
- }, null);
- }
- public static void move(int x, int y) {
- ahk("MouseMove, " + x + ", " + y);
- }
- public static int search(int x1, int y1, int x2, int y2, int tolerance, String path) {
- try {
- ahk("ImageSearch, FoundX, FoundY, " + x1 + "," + y1 + "," + x2 + ", " + y2 + ",*" + tolerance + " C:\\Users\\Preston\\Pictures\\Screenshots\\" + path);
- ahk("Clipboard = %ErrorLevel%\n");
- System.out.println(waitForClipboardChange(2000));
- return Integer.parseInt(waitForClipboardChange(2000).toString());
- } catch (Throwable T) {
- T.printStackTrace();
- return search(x1, y1, x2, y2, tolerance, path);
- }
- }
- public static boolean control() {
- try {
- NativeCall.init();
- init();
- return true;
- } catch (Throwable t) {
- t.printStackTrace();
- System.out.println("\n" + "Something went wrong...");
- return false;
- }
- }
- public static void init() {
- IntCall textdll = new IntCall("AutoHotkey.dll", "ahktextdll");
- textdll.executeCall(new Object[]{"", "", ""});
- exec = new IntCall("AutoHotkey.dll", "ahkExec");
- }
- public static void ahk(String code) {
- exec.executeCall(code);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement