自动检测/点击图像 [英] Automaticly detecting/clicking images

查看:64
本文介绍了自动检测/点击图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我需要一些申请方面的帮助。我已经遵循了一些关于如何制作自动转换器的教程,它工作正常。我需要的,并且找不到任何教程,是我的自动跟踪器自动检测图像(或某些像素)并以给定秒的间隔自动点击它(我已经有了)。



目前我对如何做到这一点毫无头绪,我已经尝试过搜索教程但却找不到任何教程。任何帮助将不胜感激。



此致,



Karlo。

Hello,

I'm in need of some help with an application. I've followed some tutorials here on how to make an autoclicker and it works fine. What I'm in need of, and can't find any tutorial about, is that my autoclicker automaticly detects an image (Or certain pixels)and automaticly clicks it with an interval of given seconds (I already have that).

Currently I'm clueless on how to do this, I've tried searching for tutorials but couldn't find any. Any help would be appreciated.

Sincerely,

Karlo.

推荐答案

这对初学者来说将是一项重要的工作。您无法单独使用.NET Framework。您将需要平台调用本机函数。



Visual Studio包含一个名为Spy ++的工具。 Spy ++将向您显示树中当前会话中加载的所有用户控件。它提供了每个控件的详细信息,包括其类型,句柄,位置等。了解如何使用此工具。然后,运行游戏并检查包含图像的控件以确定其类型(类名称)。





第一个选项:



在您的应用程序中,您需要声明p / invoke函数和数据结构,以允许您调用EnumWindows / EnumChildWindows和SendMessage。有关功能和数据签名,请参阅MSDN。访问www.pinvoke.net,了解如何编写相关的C#。



基本上,您需要监视进程创建以检测游戏何时启动。使用Framework的Process.GetProcessByName和游戏进程的名称。从生成的Process实例中,检索主窗口句柄(Process.MainWindowHandle)。然后,调用传递此句柄的EnumWindows / EnumChildWindows来监视通过Spy ++检查确定类名的任何控件的创建。最后,使用控件的句柄调用SendMessage来发送WM_LBUTTONDOWN / WM_LBUTTONUP /等。



Pro:可以完全用C语言编写

Con:将托管回调传递给本机函数意味着要了解更多关于.NET垃圾回收的信息,而不是在这个阶段你可能想要了解





第二个选项:



编写一个C / C ++ DLL,它挂钩到所有进程中的窗口(控件)创建。看看SetWindowsHookEx + WH_CBT。这个DLL应该公开函数来启动和停止钩子。然后,从您的C#应用​​程序调用这些函数。在您的CBTProc中,当您检测到显示图像的控件的创建时,使用控件的句柄和WM_LBUTTONDOWN / WM_LBUTTONUP调用SendMessage。



Pro:更直接

Con:必须编写C ++才能安装全局挂钩
This is going to be a significant amount of work for a beginner. You are not going to be able to use the .NET Framework alone. You are going to need to platform-invoke native functions.

Visual Studio includes a tool called Spy++. Spy++ will show you all of the user controls loaded in the current session in a tree. It provides details for each control, including its type, handle, location, etc. Learn how to use this tool. Then, run the game and inspect the control that contains the image to determine its type (class name).


First option:

In your application, you will need to declare p/invoke functions and data structures to allow you to call EnumWindows/EnumChildWindows and SendMessage. Refer to MSDN for the function and data signatures. Go to www.pinvoke.net to see how to write the relevant C#.

Essentially, you will want to monitor process creation to detect when the game is launched. Use the Framework's Process.GetProcessByName with the name of the game process. From the resultant Process instance, retrieve the main window handle (Process.MainWindowHandle). Then, call EnumWindows/EnumChildWindows passing this handle to monitor creation of any control that has the class name determined by inspection through Spy++. Finally, call SendMessage with the handle of the control to send WM_LBUTTONDOWN / WM_LBUTTONUP / etc.

Pro: Can be written entirely in C#
Con: Passing a managed callback to a native function means learning more about .NET garbage collection than you probably want to at this stage


Second option:

Write a C/C++ DLL that hooks into window (control) creation in all processes. Look at SetWindowsHookEx + WH_CBT. This DLL should expose functions to start and stop the hook. Then, p/invoke these functions from your C# application. In your CBTProc when you detect the creation of the control that displays the image, call SendMessage with the control's handle and WM_LBUTTONDOWN / WM_LBUTTONUP.

Pro: More direct
Con: Must write C++ in order to install global hook


这篇关于自动检测/点击图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆