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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With