Jump to content

Recommended Posts

I didn't like the search time of Simple Native Image Search, and being on windows 10 64bit, I couldn't get ImageSearchDll.dll to work properly.

So I started researching image search routines and found this excellent post and set of replies find-a-bitmap-within-another-bitmap.

I really liked the pattern that the Simple Native Image Search used, the clipboard usage and the method of searching. Although I think it could be improved by using some short circuit techniques to return sooner, like consecutive matched > 65% return | matched total > 85% return) , and I wanted the function to manage the click on the found image as well.

So I just did a bit more research and a few trips to MSDN and stackoverflow, these two snippets allow me to replicate KyleJustKnows code, and click.  Another feature is that it also saves the image it captures to disk, so that if the image is not found you can check what was captured, and alternatively cut out a new search image to use.

private void PrintScreen()
            keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0);
            keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0);

        public Bitmap CaptureScreenPrtSc()

            if (Clipboard.ContainsImage())
                using (Image img = Clipboard.GetImage())
                    img.Save("ClipBoard.PNG", ImageFormat.Png);
                    return new Bitmap(img);
            return default;
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool GetCursorPos(out MousePoint lpMousePoint);

        private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);

        private MousePoint GetCursorPosition()
            var gotPoint = GetCursorPos(out MousePoint currentMousePoint);
            if (!gotPoint) { currentMousePoint = new MousePoint(0, 0); }
            return currentMousePoint;

        private void MouseEvent(MouseEvents value)
            MousePoint position = GetCursorPosition();


So after managing to compile the dll with COM support, with much reading of this forum and many posts from paulpmeierptrexLarsJ, and others about loading .net, I managed to get this all working.

Here is the BotIt Core:

;   BotIt Core

Global $sPath = "BotIt.dll"

Global $RegAsmPath = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe"

Func BotIt_StartUp()
EndFunc   ;==>BotIt_StartUp

Func RegisterBotIt()
    RunWait($RegAsmPath & " /register /codebase /tlb " & $sPath, @ScriptDir, @SW_HIDE)
EndFunc   ;==>RegisterBotIt

Func UnregisterBotIt()
    RunWait($RegAsmPath & " /unregister " & $sPath, @ScriptDir, @SW_HIDE)
EndFunc   ;==>UnregisterBotIt

Func ActivateAndSearch($sTitle, $sImgPath, $bClick = True)
    $oBotIt = ObjCreate("BotIt.DetectImageAndClick")
    ConsoleWrite($sImgPath & @CRLF & $bClick & @CRLF)
    $bRet = $oBotIt.FindAndClick($sImgPath, $bClick)
    Return $bRet
EndFunc   ;==>ActivateAndSearch



    Until ActivateAndSearch("Window Title", "PathToFile")

I hope you enjoy!





Edited by ScrapeYourself
spelling / wording
Link to post
Share on other sites

This thread will be closed 99% anyway (forum rules), but that is not the reason for my contribution.

Warning : Never download and execute a .dll from an unknown source.


"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

After reading the rules this is not about botting a game, or has anything to do with a game.

rules as I see them.

  • Malware of any form - trojan, virus, keylogger, spam tool, "joke/spoof" script, etc.
  • Bypassing of security measures - log-in and security dialogs, CAPTCHAs, anti-bot agents, software activation, etc.
  • Automation of software/sites contrary to their EULA (see Reporting bullet below).
  • Launching, automation or script interaction with games or game servers, regardless of the game.
  • Running or injecting any code (in any form) intended to alter the original functionality of another process.
  • Decompilation of AutoIt scripts or details of decompiler software

This tool is not used for anything more then what it is intended to do..Find and click a image on the screen.

I provided source code for self compilation in first post.



Edited by ScrapeYourself
Link to post
Share on other sites


9 minutes ago, ScrapeYourself said:

After reading the rules this is not about botting a game, or has anything to do with a game.

Fortunately, that's not my decision. I just wanted to inform (especially inexperienced) users not to start executables, if the origin is possibly uncertain ;).


"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
13 minutes ago, ScrapeYourself said:

I still want to understand further, why you think 99 % it will be closed :( 
what can i do to change that?

It is best to wait and see how a moderator judges this issue. If there are no objections, the thread will not be closed ;). But I have experienced in the past that threads about "Pixelsearch", "Imagesearch" and similar operations are considered very strictly.

Edited by Musashi


"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
  • Developers

We leave this thread open for now, but make sure it will adhere to our forum rules. :) 


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

Link to post
Share on other sites
  • Jos unlocked this topic

Thank you Jos,


To clear any misunderstanding in my names of images searched, I am working on a deductions processing website as a side job. All parties are aware of automation.

One of the issues I experience isI search these 2 images in sequence to ensure I end on the SIS inquery tab and search.

If not Automation Scripts\SISInquiry.PNG then
    If Automation Scripts\PaymentInquiry.PNG then
        Automation Scripts\SISInquiry.PNG

Automation Scripts\RegisterBotIt.au3" (56) : ==> Variable must be of type "Object".:

$bRet = $oBotIt.FindAndClick($sImgPath,    $Region, $bClick)
$bRet = $oBotIt^ ERROR

But it occassionally fails on the 2nd search with the error above, how can i detect that before it occurs, would IsObj Work?


My next question is what pattern could we use to compress the searched for image to a small set of coords and values to identify?

Edited by ScrapeYourself
spelling / wording
Link to post
Share on other sites

You need to do much more error checking!
Means: When you call a function that creates an object make sure, the result is an object. Most of the time this is being done by implementing a COM error handler (see ObjEvent in the help file).

For examples check the Excel or Word UDF.

My UDFs and Tutorials:


Active Directory (NEW 2021-11-10 - Version - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version - Download
Outlook Tools (2019-07-22 - Version - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

ADO - Wiki
WebDriver - Wiki


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By moooe
      There is an API for hardware, which is implemented through Lusbapi.dll
      In the C ++ reference it looks like this:
      1) if (GetDllVersion() != 2) { printf("error 1"); }
      2) pModule = static_cast<ILE440 *>(CreateInstance("e440"));
      if (pModule == NULL) { printf("error 2"); }
      3) if (!pModule->GetModuleName()) { printf("error 3"); }

      For AutoIt I rewrote:
      $hDLL = DllOpen('Lusbapi.dll')
      1) $aRes = DllCall($hDLL, 'LRESULT', 'GetDllVersion')
      if $aRes[0] <> 2 then Exit
      2) $tDeviceName = DllStructCreate("char DeviceName[9]")
      DllStructSetData($tDeviceName, "DeviceName", 'e440')
      $aRes = DllCall($hDLL, 'PTR', 'CreateLInstance', 'STRUCT*', $tDeviceName)
      $pModule = $aRes[0]
      if $pModule == Null then Exit
      3) At this step, the error
      $aRes = DllCall($hDLL, 'PTR', 'GetModuleName')
      The function GetModuleName was not found (since this is a method from the CreateLInstance function), I could not implement a call to the method
    • By Colduction
      Hi AutoIt programmers, excuse me for bothering you with multiple topics.

      In AutoIt we can use Number() function to convert Hex string to number but it's output is different of C# output & and i wanna make it's output like AutoIt code.

      For e.g I use this in AutoIt:
      Local $dBinary = Binary("Hello") ; Create binary data from a string. Local $dExtract = Number(BinaryMid($dBinary, 1, 5)) ConsoleWrite($dExtract & @CRLF) And i use this for C#:
      using System; using System.Text; //NameSpace Is Use of Project Name namespace TEST { class Program { public static void Main(string[] args) { //declaring a variable and assigning hex value string dd = ToHex("Hello", Encoding.ASCII); decimal d = Int64.Parse(dd, System.Globalization.NumberStyles.HexNumber); Console.WriteLine("Result: " + d); //hit ENTER to exit Console.ReadLine(); } public static string ToHex(string sInput, Encoding oEncoding, bool b0x_Prefix = false) { byte[] a_binaryOutput = oEncoding.GetBytes(sInput); string sOutput = BitConverter.ToString(a_binaryOutput).Replace("-", ""); if (b0x_Prefix == false) { return sOutput; } else { return "0x" + sOutput; } } } }
      I say once again that excuse me for creating new topic, in fact i'm making a library for GAuthOTP from a topic in AutoIt.
    • By Aelc
      Hey there,
      I'm trying to create an DLL callback loop to get an updated screen (actually just 1 pic that should refresh because i already got a screencapturetool to get a pic from my game every sec)
      i want to bring that pic on a mobile phone. the dll can connect with the program i'm using to get the connection so that's fine.
      The prob is: it's my first DLL project so i don't even get 1 call or other returns of it. I tried much with the examples but i can't compare it that much with it.
      The calls shall be with c# where i'm not familiar with... i just searched much in forums and programsites but i didn't get a reference point.
      could someone have a tip to start please?
      there are calls like
      [DllImport("file.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] public static extern bool $funcname1(String identifier, String friendlyName, ref CbConext callback);
      [DllImport("file.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] public static extern bool $funcname2(String identifier, String friendlyName, ref logiArxCbContext callback, byte [] iconBitmap);
      [DllImport("file.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] public static extern bool $funcname3(String filePath, String fileName, String mimeType = "");
      tried something like
      $dll = DllOpen ("file.dll")
      $call = DllCall ( $dll,"bool","$funcname1","str","indetifier","str","test","int","CbContext callback" )
      or have i work with dllstructcreate or dllcallbackregister? 
      it would be enough for me if someone just could explain me how to get the imports with the params/funcs/types in autoit.
      i don't know if it's important but u shall call 
      public classes and public constants in c# before such as using.system make this sense?
      sry for my bad english 
      and thank you in advance
    • By DiegoCorradini
      Hi all,
      I have a problem to handle the controls of an application.
      Using AutoIT Windows Tool I can get only the Window (see Summary of the picture).
      Any tips to get the controls without knowing the name?
      (PS Using TestStack.White everything works, however I want the HIDE application feature of AutoIT). 
      Many thanks

    • By IgImAx
      UPDATED Notes: ===============================================================================
      UPDATED: My main and second questions answered. Here the answers:
      To add/access WinMenuSelectItem you need to [Thanks to Fernando_Marinho]: Add AutoItX.Dotnet in Manage NuGet Packages Right Click in your Project -> Add -> Reference... -> COM ( Type Libraries )than, check the option AutoItX3 1.0 Type Library  using AutoItX3Lib; AutoItX3 au3 = new AutoItX3(); au3.WinMenuSelectItem("", ...) My full source code in C# exists in 11 posts in below. How to access those overloaded methods in AutoitX3 that are not accessible via above method!? Or how to fix AutoitX3 DLL Registration need in target computers without Autoit pre-installed on them!? Please check my post at 14 posts below!
      =============================================================================== Original Post:
      I was writing a small app in Autoit to close µTorrent app. It was working. Then I try to import AutoItX into C#, but unfortunately this method
      WinMenuSelectItem Couldn't find by IntelliSense and If I typed completely it still give me this message:
      Please check the image. I Google it and I found this QA at stackoverflow: Autoit error within C# application I saw they use this line:
      au = new AutoItX3Lib.AutoItX3Class(); I figure it how to add 'AutoItX3Lib' to project (by adding 'AutoItX3.dll' to reference) but again! When I use this line:
      var au = new AutoItX3Class(); I got this error message: Interop type 'AutoItX3Class' cannot be embedded. Use the applicable interface instead.
      My system info:
      Visual Studio 2017 Enterprise - v15.5.4
      X64 Windows 10 Enterprise 1607
      Thanks in advanced

  • Create New...