views:

1585

answers:

2

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 minesweepers)

So it works for minsweepers and doesn't require it to be the active window. When I try to make it work on my flash game it requires the IE 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.

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: Pretty sure this has something to do with the way the handle gets passed, I've done some tests with calling an autoit exe 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.

+1  A: 

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.

Lucas McCoy
+3  A: 

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.

Copas
thanks I will definitely look into those ressourcesI 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 me
Jean-Bernard Pellerin
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 you
Jean-Bernard Pellerin