So, bots with AutoIT. That's lame.
Why learn a pointless and worthless language, that will only get you mocked when you finally have that foolish "Oh, I program too!" moment, only to reveal.. You use AutoIT.
In all seriousness though, I think it'll be interesting to see what people do with a more versatile language, like C#.
It'll probably also be harder for AHN Labs to blanket detect, like AHK was, all that time ago. Maybe.
Yes, this is a console application, I clicked the wrong project type, and couldn't be bothered to change it/make a new project.
That's how fucking lazy I am.
Deal with it.
The Mouse_event function will probably be more effective with a windows form program, as I understand it, and I might even bother to test it one day.
ONE DAY.
I should probably say now, this was about 5-10 mins of half assed work, it's just a proof of concept really, that concept being "You don't need to use AutoIT to use ImageSearch".
Also, it's probably quite useful as a general guide/starting point.
Inb4: Infraction.
This post isn't really on topic with the thread title, and I'm technically asking a question, in a section that says "I won't post a question or other non-releases in this forum.", and John loves to be petty <3
Why learn a pointless and worthless language, that will only get you mocked when you finally have that foolish "Oh, I program too!" moment, only to reveal.. You use AutoIT.
In all seriousness though, I think it'll be interesting to see what people do with a more versatile language, like C#.
It'll probably also be harder for AHN Labs to blanket detect, like AHK was, all that time ago. Maybe.
Yes, this is a console application, I clicked the wrong project type, and couldn't be bothered to change it/make a new project.
That's how fucking lazy I am.
Deal with it.
The Mouse_event function will probably be more effective with a windows form program, as I understand it, and I might even bother to test it one day.
ONE DAY.
I should probably say now, this was about 5-10 mins of half assed work, it's just a proof of concept really, that concept being "You don't need to use AutoIT to use ImageSearch".
Also, it's probably quite useful as a general guide/starting point.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
//using System.Drawing;
namespace Image_Search_Test
{
class Program
{
[DllImport("ImageSearchDLL.dll")]
static extern string ImageSearch(int aLeft, int aTop, int aRight, int aBottom, string aImageFile);
//Examples of the use of the DLL's ImageSearch Function, in C#:
//ImageSearch(0, 0, 1920, 1080, "*250 Capture.JPG") this is a search across the entire screen, starting at topX = 0, topY = 0, bottomX = 1920, bottomY = 1080. The search system uses a simple space based system for tolerance and transparancy,
//but assumes that if there is only one value, that you wish to deal with tolerance only. If you wanted to deal with both in a search, it would look like this:
//ImageSearch(0, 0, 1920, 1080, "*250 *100 Capture.JPG")
//This is a search with 250 tolerance, and 100 transparency. The * and the space following the value mark it as not part of the filename.
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetCursorPos(int X, int Y);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
static string str;
static void Main(string[] args)
{
str = ImageSearch(0, 0, 1920, 1080, "*120 Capture.JPG");
if (str.Split('|')[0] == "1")
{
Console.WriteLine("Found!");
Console.WriteLine(str);
Console.WriteLine("X: " + str.Split('|')[1]);
Console.WriteLine("Y: " + str.Split('|')[2]);
SetCursorPos(Convert.ToInt32(str.ToString().Split('|')[1]), Convert.ToInt32(str.ToString().Split('|')[2]));
DoMouseClick();
}
else
{
Console.WriteLine("Not found. Try adjusting the tolerance.");
}
Console.Read();
}
static void DoMouseClick()
{
//Cursor.Position = new Point(Convert.ToInt32(str.Split('|')[1]), Convert.ToInt32(str.Split('|')[2]));
//mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, Convert.ToInt32(str.ToString().Split('|')[1]), Convert.ToInt32(str.ToString().Split('|')[2]), 0, 0); //supposed to move cursor to location and click, but only simulates click at current location.
}
}
}
//The original functions in autoIT format (From the ImageSearch.au3), for reference
//Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance,$transparency=0)
// return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$transparency)
//EndFunc
//Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance, $transparency=0)
// ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
// if not ($transparency = 0) then $findImage = "*" & $transparency & " " & $findImage
// if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
// $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
// ; If error exit
// if $result[0]="0" then return 0
// $array = StringSplit($result[0],"|")
// $x=Int(Number($array[2]))
// $y=Int(Number($array[3]))
// if $resultPosition=1 then
// $x=$x + Int(Number($array[4])/2)
// $y=$y + Int(Number($array[5])/2)
// endif
// return 1
//EndFunc
Inb4: Infraction.
This post isn't really on topic with the thread title, and I'm technically asking a question, in a section that says "I won't post a question or other non-releases in this forum.", and John loves to be petty <3