Outshynd Posted January 11, 2007 Share Posted January 11, 2007 (edited) I wrote this for another forum but I figured I'd post it here as well. Hopefully it'll help some poor, lost soul.C# is a much faster and more complete language than AutoIt. That said, it's also far more difficult to do simple tasks that AutoIt does quite well. You have to write your own MouseMove functions, your own WinActivate functions, your own everything functions (nearly). This is because AutoIt is a Windows automation tool and C# is an actual programming language. Well, can we have the best of both worlds? Sure.This describes how to add AutoItX (the AutoIt COM Library DLL) to your C# (or other .NET) project and then execute a few simple instructions.http://www.nomorepasting.com/paste.php?pasteID=72980expandcollapse popupusing System; using System.Threading; namespace AutoItXTest { class Program { static AutoItX3Lib.AutoItX3Class au3; //our au3 class that gives us au3 functionality static Thread thread; //our thread static bool threadshouldexecute = true; //only execute thread 2 while this equals true static int i = 0; //our incrementer /// <summary> /// The entry point, or main thread / main loop, of our program /// </summary> static void Main(string[] args) { au3 = new AutoItX3Lib.AutoItX3Class(); //initialize our au3 class library au3.AutoItSetOption("WinTitleMatchMode", 4); //advanced window matching thread = new Thread(new ThreadStart(threadtest)); //initialize and start our thread thread.Start(); if (au3.WinExists("Untitled - Notepad", "") == 0) //if an Untitled - Notepad document doesn't exist au3.Run(@"C:\WINDOWS\SYSTEM32\notepad.exe", "", au3.SW_SHOW); //run notepad else au3.WinActivate("Untitled - Notepad", ""); //otherwise activate the window string hWnd = ""; //let's use a window handle while (hWnd.Length == 0) //try to get a handle to notepad until it succeeds hWnd = au3.WinGetHandle("Untitled - Notepad", ""); while (au3.WinActive("handle=" + hWnd, "") == 0) //loop while it's not active { au3.WinActivate("handle=" + hWnd, ""); //and activate it Thread.Sleep(100); } while (au3.WinExists("handle=" + hWnd, "") != 0) //while the window exists, loop { //send our incrementing variable, i, to notepad, with a trailing | au3.ControlSend("handle=" + hWnd, "", "Edit1", i.ToString() + "|", 0); i++; //increment i Thread.Sleep(100); //short sleep so we don't burn CPU } //if the while loop exited--because there's no Untitled - Notepad--make the other thread stop executing threadshouldexecute = false; Console.Write("Press [ENTER] to continue..."); //tell the user to press ENTER to quit Console.ReadLine(); //pause until enter is pressed } /// <summary> /// our void function to execute thread #2 /// </summary> static void threadtest() { while (threadshouldexecute) //loop while this thread should execute { au3.ToolTip("Thread 2\ni: " + i.ToString(), 0, 0); //display a tooltip with the incrementing variable i in it Thread.Sleep(50); //sleep to free up CPU } au3.ToolTip("", 0, 0); //clear the tooltip after loop is done } } } Edited July 14, 2007 by Outshynd Piyu 1 Link to comment Share on other sites More sharing options...
Richard Robertson Posted January 12, 2007 Share Posted January 12, 2007 I fail to see the point in the second thread just for a tool tip. Better programmers could have done both in the main loop. Good job on the walkthrough, but I don't know how many people have trouble referencing the component. Link to comment Share on other sites More sharing options...
Outshynd Posted January 13, 2007 Author Share Posted January 13, 2007 I fail to see the point in the second thread just for a tool tip. Better programmers could have done both in the main loop.Good job on the walkthrough, but I don't know how many people have trouble referencing the component.I fail to see the point in a program that spams keypresses in notepad. Maybe, just maybe, it was an example. How many people love the functionality of AutoIt but want multithreading? Holy shit, now maybe someone who doesn't have as much expertise can figure out how to do it.Referencing the component may not be super difficult but for someone who's just picking up a C# IDE--especially someone whose only coding experience is in AutoIt, as with many of the people who visit this site--may find it slightly helpful to know how to add AutoItX3 to their project without having to come to the forums and ask. Did I have a problem with it? No. Am I so arrogant to think that no one else will have a problem with it? No. Do I really want to read and answer multiple threads/questions on how to reference the DLL? No. Did it hurt to take three small screenshots and upload them to a website? No. I don't see the problem here.While I appreciate the commendation, the negativity isn't needed. Link to comment Share on other sites More sharing options...
Xenthalon Posted January 30, 2007 Share Posted January 30, 2007 It really was helpful for me. Exactly as Outshynd described I had quite some experience with AutoIt but just learned the basics of C++ some weeks ago and had no idea how to implement a dll and how to use it, so this tutorial is very very usful for me. Thanks Outshynd Link to comment Share on other sites More sharing options...
Richard Robertson Posted January 30, 2007 Share Posted January 30, 2007 All I was saying is that this is an AutoIt forum, not a .Net forum. They shouldn't need to come here for .Net questions. Don't bring multithreading into this. Valik has clearly explained, several times, why multithreading is not going to happen until a major revamp, if ever. Link to comment Share on other sites More sharing options...
amokoura Posted February 21, 2007 Share Posted February 21, 2007 This was a nice help for me because I was wondering how hard is it to embed AutoIt in other languages. Apparently it isn't! Link to comment Share on other sites More sharing options...
korifg Posted March 12, 2007 Share Posted March 12, 2007 This is a very good tutorial. Now it is easy to access Autoit features from other language. Link to comment Share on other sites More sharing options...
Jace Posted March 12, 2007 Share Posted March 12, 2007 Thanks! Link to comment Share on other sites More sharing options...
Harusal Posted February 11, 2009 Share Posted February 11, 2009 This works great! but how would i do #include blah.au3 ??? Link to comment Share on other sites More sharing options...
Richard Robertson Posted February 11, 2009 Share Posted February 11, 2009 You can't include AutoIt source when you're not using AutoIt. Link to comment Share on other sites More sharing options...
jcddcjjcd Posted February 13, 2009 Share Posted February 13, 2009 For an alternate way of using AutoItX3 in C# that does not require registering have a look at this. On page 2 you will see an updated version for 3.3.0.0 which returns Unicode data. Regards, John. Link to comment Share on other sites More sharing options...
Zohar Posted March 2, 2009 Share Posted March 2, 2009 looks cool. I wish AutoIt was .NET by nature, that way allllll functions and code libraries(UDFs) could be accessed. Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 2, 2009 Share Posted March 2, 2009 The development team has no interest in doing that. I've been working on an AutoIt.Net variation but it's a side project and I just really haven't had the time. Link to comment Share on other sites More sharing options...
Zohar Posted April 12, 2009 Share Posted April 12, 2009 mmm how far did you go with it? Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 12, 2009 Share Posted April 12, 2009 As of right now, the project was recently scrapped and restarted. So you tell me. Link to comment Share on other sites More sharing options...
Zohar Posted April 13, 2009 Share Posted April 13, 2009 oh :/ Link to comment Share on other sites More sharing options...
Gwen2 Posted April 30, 2009 Share Posted April 30, 2009 I use SharpDevelop and when I try to add reference I have no "Browse" tab. I have only "GAC", "Projects", ".NetAssembly browser" and "COM" tabs. Could you please to instruct me how to add reference to the AutoItX3.dll? Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 30, 2009 Share Posted April 30, 2009 You can't reference COM directly in .Net. You have to build a wrapper assembly around it or call the COM interop methods yourself. Link to comment Share on other sites More sharing options...
justdoit123 Posted June 16, 2009 Share Posted June 16, 2009 You can't reference COM directly in .Net. You have to build a wrapper assembly around it or call the COM interop methods yourself.come on,i don't know how to do it,tell more... Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 16, 2009 Share Posted June 16, 2009 Try being more polite and using correct sentence structure. Have you tried searching the MSDN for accessing COM in .Net languages? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now