简体   繁体   English

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

[英]Sending messages to a Flash game with C# and AutoIt

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. 我正在为Flash游戏制作机器人,我已经想出如何将所有AutoIt函数导入到我的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);
}

(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. 当我尝试使其在我的Flash游戏上运行时,它需要Internet Explorer窗口是活动的。 Is this something Flash requires or is there something additional that I could do to make it work when the game is minimized? 这是Flash需要的东西还是还有一些额外的功能可以让游戏最小化时使其工作?

This doesn't have to be done using the AutoIt imports. 这不必使用AutoIt导入来完成。 I tried SendMessage from user32 at one point also, but that didn't work for Flash content at all for me. 我也曾在user32尝试过SendMessage ,但这对我来说根本不适用于Flash内容。

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... 我刚刚在随机网站上测试了这个,而不是Flash网站或Minesweeper,并且出于某种原因,如果我从Autoit脚本程序中执行它,而不是来自我的C#程序,代码可以正常运行...

June 20th, 2012 : I am pretty sure this has something to do with the way the handle gets passed. 2012年6月20日 :我很确定这与句柄传递的方式有关。 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. 我已经做了一些测试,调用AutoIt EXE文件,并使用我从C#代码获取的句柄作为参数,我必须添加一个0x ,然后在AutoIt代码中我必须从字符串中转换它到一个HWnd,所以这可能是某种东西,在这种情况下我不知道该怎么做,因为导入的函数依赖于句柄的字符串输入。

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. 应该没有必要使用WinGetTitle“扫雷”窗口标题应该可以正常工作。 According to my AutoIt v3 Window Info tool in Windows 7 the title and class of Minesweeper window are both Minesweeper. 根据我在Windows 7中的AutoIt v3窗口信息工具,Minesweeper窗口的标题和类别都是扫雷。 So hard coding 如此难以编码

auto.ControlClick("[TITLE:Minesweeper; CLASS:Minesweeper], "", "", "left", 2, r * 10, r * 10); 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. 有关其工作原理的更多信息,请参阅AutoIt帮助文件中的高级窗口描述 If this still isn't working look up WinTitleMatchMode in the help file. 如果仍然无法正常工作,请在帮助文件中查找WinTitleMatchMode 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. AutoIt X是AutoIt的DLL / COM控件版本,它是如何将AuotIt添加到任何具有DLL / COM支持的语言。 In case anyone else was wondering how you would use AutoIt in C# . 如果其他人想知道如何在C#中使用AutoIt Unfortunately AutoIt X often lags behind in development and testing from the main language. 不幸的是,AutoIt X在主要语言的开发和测试中经常落后。 Although have no reason to think your problem is caused by a bug just giving some background on the AutoItX project. 虽然没有理由认为你的问题是由一个错误引起的,只是给出了AutoItX项目的一些背景知识。 If you haven't already you should post a copy of this question to the ActiveX/COM Help and Support (AutoItX) forum. 如果您还没有,则应将此问题的副本发布到ActiveX / COM帮助和支持(AutoItX)论坛。 One the the best things about AutoIt in my experience over the years is the community (which hasn't moved here much). 在我多年来的经验中,关于AutoIt的最好的事情之一就是社区(它没有在这里移动太多)。 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. 至于6月20日的注释,AutoIt会将所有变量视为字符串,直到它检测到它的特殊情况为止。 It doesn't know a value is hex unless it starts with the 0x you mentioned. 它不知道值是十六进制,除非它以你提到的0x开头。 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. 我有几次不得不在变量中添加零以使AutoIt在之后正确评估它。 This doesn't happen often with AutoIt3 but just something to keep in mind. AutoIt3不会经常发生这种情况,但要记住这一点。

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. 如果您需要任何AutoIt参考代码, AutoIt论坛的大量成员已经制作了Minesweeper机器人,您可以查看并可能看到有用的东西。

Make sure your running your C# program as admin. 确保以管理员身份运行C#程序。 This is the only difference I can see for one method working and the other not. 这是我能看到的一种方法工作的唯一区别,而另一种方法则没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM