Sending messages to a Flash game with C# and AutoIt
Asked Answered
O

2

6

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.

Orobanchaceous answered 9/5, 2009 at 20:47 Comment(2)
How did you export autoit functions to c#? I'm just curious.Seat
lancelarsen.com/Blog/tabid/72/EntryId/48/… Theres a site with ressources where somebody has made a class importing the functions from the DLL library. But I think that if you just include the library you don't necessarily need to use that class he made. I say that because his helper class doesn't include all the functions as imports but you are able to access all autoit methods anyways.Orobanchaceous
M
4

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.

Mayapple answered 21/6, 2009 at 14:50 Comment(2)
thanks I will definitely look into those ressources I was just using minesweeper to learn though, and this still doesn't resolve my issue of the flash game. But I'll do some more tinkering with what you've shown meOrobanchaceous
well time's just about up, so I'm giving you the bounty even though I'm not fully satisfied I was hoping to find out how to click onto a webbrowser, I could already do it in minesweeper as I explained But yours was the best of available answers thank youOrobanchaceous
R
1

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.

Rubellite answered 20/6, 2009 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.