使用 C# 和 AutoIt 向 Flash 游戏发送消息

发布于 2024-07-19 12:40:33 字数 1369 浏览 5 评论 0原文

我正在为 Flash 游戏制作一个机器人,并且我已经弄清楚如何导入所有 AutoIt< /a> 函数进入我的 C# 代码。

string title = "Minesweeper";
string full = auto.WinGetTitle(title,"");
string handle = auto.WinGetHandle(full, "");
if (auto.WinExists(full, "") == 1)
    textBox1.Text = "window exists";
addressBox.Text = full;

for (int r = 1; r < 40; r++)
{
    auto.ControlClick(full, "", "", "left", 2, r * 10, r * 10);
    //auto.ControlClick(handle, "", "", "left", 2, r * 10, r * 10);
}

(我很确定未注释的应该是带有句柄的,反之亦然,但这适用于 扫雷。)

因此它适用于扫雷,并且不需要它是活动窗口。 当我尝试让它在我的 Flash 游戏上运行时,它需要 Internet Explorer 窗口成为活动窗口。 这是 Flash 所需要的,还是我可以做一些额外的事情来使其在游戏最小化时正常工作?

这不必使用 AutoIt 导入来完成。 我尝试了 SendMessage 也曾一度来自 user32,但这对我来说根本不适用于 Flash 内容。

我只是在随机网站而不是 Flash 网站或扫雷中测试了此代码,并且出于某种原因,如果我从 Autoit 脚本程序中执行代码,而不是从我的 C# 程序中执行代码,则该代码可以工作...

2012 年 6 月 20 日< /strong>:我很确定这与句柄的传递方式有关。 我已经完成了一些测试,调用 AutoIt EXE 文件并使用从 C# 代码获得的句柄作为参数,我必须向其中添加 0x ,然后在 AutoIt 代码中添加必须将其从字符串转换为 HWnd,因此这可能是某种情况,在这种情况下我不知道该怎么做,因为导入的函数依赖于句柄的字符串输入。

I'm making a bot for a Flash game, and I've figured out how to import all the AutoIt functions into my C# code.

string title = "Minesweeper";
string full = auto.WinGetTitle(title,"");
string handle = auto.WinGetHandle(full, "");
if (auto.WinExists(full, "") == 1)
    textBox1.Text = "window exists";
addressBox.Text = full;

for (int r = 1; r < 40; r++)
{
    auto.ControlClick(full, "", "", "left", 2, r * 10, r * 10);
    //auto.ControlClick(handle, "", "", "left", 2, r * 10, r * 10);
}

(I'm pretty sure the uncommented one should be the one with handle and vice versa, but this works for Minesweeper.)

So it works for Minesweeper and doesn't require it to be the active window. When I try to make it work on my Flash game it requires the Internet Explorer window to be the active one. Is this something Flash requires or is there something additional that I could do to make it work when the game is minimized?

This doesn't have to be done using the AutoIt imports. I tried SendMessage from user32 at one point also, but that didn't work for Flash content at all for me.

I just tested this on a random website instead of a Flash site or Minesweeper and for some reason the code works if I execute it from within the Autoit scripting program, but not from my C# program...

June 20th, 2012: I am pretty sure this has something to do with the way the handle gets passed. I've done some tests with calling an AutoIt EXE file and using the handle I get from the C# code as an argument, I have to add an 0x to it, and also then within the AutoIt code I have to cast it from a string to an HWnd, so that could be something, in which case I don't know what to do since the imported function relies on a string input for the handle.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书间行客 2024-07-26 12:40:33

您可能想尝试排除窗口句柄和变量处理问题。 不需要使用 WinGetTitle,“扫雷”窗口标题应该可以正常工作。 根据我在 Windows 7 中的 AutoIt v3 窗口信息工具,扫雷窗口的标题和类别都是扫雷。 所以硬编码

auto.ControlClick("[标题:扫雷;
类别:扫雷], "", "", "左", 2,
r*10,r*10);

可能会起作用。 有关其工作原理的更多信息,请参阅 AutoIt 帮助文件中的高级窗口描述。 如果这仍然不起作用,请在帮助文件中查找 WinTitleMatchMode。 它允许您在窗口标题匹配中设置一些宽松的规则,这可以使您更轻松地进行操作。

AutoIt X 是 AutoIt 的 DLL/COM 控制版本,您可以通过它将 AuotIt 添加到任何具有 DLL/COM 支持的语言中。 如果其他人想知道如何在 C# 中使用 AutoIt。 不幸的是,AutoIt X 在主要语言的开发和测试方面经常落后。 尽管没有理由认为您的问题是由错误引起的,但只是提供了 AutoItX 项目的一些背景知识。 如果您还没有,您应该将此问题的副本发布到 ActiveX/ COM 帮助和支持 (AutoItX) 论坛。 根据我多年来的经验,AutoIt 最好的事情之一就是社区(这里并没有发生太大变化)。 该语言的一些开发人员经常光顾该特定的论坛部分,他们很乐意提供帮助。

至于您的6 月 20 日注释,AutoIt 将所有变量视为字符串,直到它检测到它有特殊之处。 它不知道值是十六进制,除非它以您提到的 0x 开头。 这在过去给我带来了各种奇怪的问题。 我曾多次不得不向变量添加零才能​​让 AutoIt 正确评估它。 AutoIt3 中不会经常发生这种情况,但请记住这一点。

如果您需要任何 AutoIt 参考代码,请使用 AutoIt 论坛制作了扫雷机器人,您可以查看一下,可能会看到一些有用的东西。

Something you may want to try to rule out window handle and variable handling issues. There should be no need to use WinGetTitle the "Minesweeper" window title should work fine. According to my AutoIt v3 Window Info tool in Windows 7 the title and class of Minesweeper window are both Minesweeper. So hard coding

auto.ControlClick("[TITLE:Minesweeper;
CLASS:Minesweeper], "", "", "left", 2,
r * 10, r * 10);

might work. For more on how that works see Advanced Window Descriptions in the AutoIt help file. If this still isn't working look up WinTitleMatchMode in the help file. It allows you to set up some rules for leniency in window title matching that could make this easier for you.

AutoIt X is AutoIt's DLL/COM control version it is how you would add AuotIt to any language that has DLL/COM support. In case anyone else was wondering how you would use AutoIt in C#. Unfortunately AutoIt X often lags behind in development and testing from the main language. Although have no reason to think your problem is caused by a bug just giving some background on the AutoItX project. If you haven't already you should post a copy of this question to the ActiveX/COM Help and Support (AutoItX) forum. One the the best things about AutoIt in my experience over the years is the community (which hasn't moved here much). That particular forum section is frequented by some of the developers of the language who would be happy to help.

As to your June 20th note, AutoIt treats all variables like strings until it detects that its something special. It doesn't know a value is hex unless it starts with the 0x you mentioned. This has caused all sorts of strange problems for me in the past. I have on several occasions had to add zero to a variable to get AutoIt to evaluate it correctly after. This doesn't happen often with AutoIt3 but just something to keep in mind.

If you need any AutoIt reference code plenty of members of the AutoIt forum have made Minesweeper bots you can check out and possibly see something helpful.

情感失落者 2024-07-26 12:40:33

确保您以管理员身份运行 C# 程序。 这是我看到的一种方法有效而另一种方法无效的唯一区别。

Make sure your running your C# program as admin. This is the only difference I can see for one method working and the other not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文