WTF Posted May 12, 2006 Share Posted May 12, 2006 A sample in C++ comes with AutoItX, could someone please do this sample in C#. #include <Windows.h> #include "AutoIt3.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // You can now call AutoIt commands, e.g. to send the keystrokes "hello" AU3_Sleep(1000); AU3_Run("notepad.exe", "", 1); AU3_WinWaitActive("Untitled -", "", 0); AU3_Send("Hello{!}", 0); // Get the text in the status bar char szText[1000]; AU3_StatusbarGetText("Untitled -", "", 2, szText, 1000); MessageBox(NULL, szText, "Text:", MB_OK); return 0; } It would be much appreciated, thank you. Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 14, 2006 Share Posted May 14, 2006 namespace AutoItTest{ publicclass AutoItTest { [system.STAThread] void Main() { // You can now call AutoIt commands, e.g. to send the keystrokes "hello" AutoItX3Lib.AutoItX3Class aix3c =new AutoItX3Lib.AutoItX3Class(); aix3c.Sleep(1000); aix3c.Run("notepad.exe", "", 1); aix3c.WinWaitActive("Untitled -", "", 0); aix3c.Send("Hello{!}", 0); // Get the text in the status bar string text = aix3c.StatusbarGetText("Untitled -", "", 2); System.Windows.Forms.MessageBox.Show(text, "Text:"); } }} Link to comment Share on other sites More sharing options...
nfwu Posted May 14, 2006 Share Posted May 14, 2006 Is the namespace necessary? Last time I used C# namespace was not required. (Just asking.) #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
WTF Posted May 14, 2006 Author Share Posted May 14, 2006 (edited) It did open Notepad but that's as far as your code got. It did not write "Hello" and it crashed my computer, had to restart. Edited May 14, 2006 by WTF Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 15, 2006 Share Posted May 15, 2006 C# is a purely .Net language. .Net classes can only exist in a namespace. Sorry about the crash. I assume you linked the AutoItX into your project correctly? Link to comment Share on other sites More sharing options...
WTF Posted May 15, 2006 Author Share Posted May 15, 2006 C# is a purely .Net language. .Net classes can only exist in a namespace.Sorry about the crash. I assume you linked the AutoItX into your project correctly?Yes, AutoItX3 is correctly referenced. Link to comment Share on other sites More sharing options...
Uten Posted May 15, 2006 Share Posted May 15, 2006 It did open Notepad but that's as far as your code got. It did not write "Hello" and it crashed my computer, had to restart.What kind of architecture are you running on? AutoItX is a 32 bit dll. Take a look at this thread. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
WTF Posted May 15, 2006 Author Share Posted May 15, 2006 What kind of architecture are you running on? AutoItX is a 32 bit dll. Take a look at this thread.32 bit. Does the sample C# code given here run for you? Link to comment Share on other sites More sharing options...
Uten Posted May 15, 2006 Share Posted May 15, 2006 32 bit. Does the sample C# code given here run for you?I dont have the NET installed anymore. but the code in the thread I provided did work for me, and finaly for TP in that thread. Sorry I could not help you out anymore Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
WTF Posted May 15, 2006 Author Share Posted May 15, 2006 (edited) //I got it to work! using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using AutoItX3Lib; namespace OpenNotePad { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private static AutoItX3Lib.AutoItX3Class autoit = new AutoItX3Lib.AutoItX3Class(); public static void Init() { autoit.AutoItSetOption("CaretCoordMode", 0); autoit.AutoItSetOption("ColorMode", 1); autoit.AutoItSetOption("MouseCoordMode", 0); autoit.AutoItSetOption("PixelCoordMode", 0); } private void btNotePad_Click(object sender, EventArgs e) { autoit.Sleep(1000); autoit.Run("notepad.exe", "", 1); autoit.WinWaitActive("Untitled -", "", 1); autoit.Send(" Hello{!}", 0); // Get the text in the status bar string text = autoit.StatusbarGetText("Untitled -", "", 2); System.Windows.Forms.MessageBox.Show(text, "Text:"); } } } Edited May 15, 2006 by WTF Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 16, 2006 Share Posted May 16, 2006 By the look of that, you have Visual Studio .Net 2005? Other than you having a form and a lot of unneccessary imports, that is the same code I gave you. Link to comment Share on other sites More sharing options...
WTF Posted May 16, 2006 Author Share Posted May 16, 2006 By the look of that, you have Visual Studio .Net 2005?Other than you having a form and a lot of unneccessary imports, that is the same code I gave you.Hi,Yes, I'm using Visual Studio.Net 2005.The only thing that I had to change in your code to make it run and not crash my machine was:aix3c.WinWaitActive("Untitled -", "", 0);autoit.WinWaitActive("Untitled -", "", 1);I have the "unnecessary imports" because I'm making a C# project that uses all of the AutoItX commands, I just forgot to remove some of the code before posting.If you have any snippets of C# code using AutoItX I sure would appreciate it, I just want to make a C# example that usese all of AutoItX.Thanks for your help. Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 17, 2006 Share Posted May 17, 2006 The program probably crashed due to timeout issues. You're quite welcome. I don't really use AutoItX. I've liked to discover and use the Windows API functions directly to reduce overhead. Link to comment Share on other sites More sharing options...
WTF Posted May 19, 2006 Author Share Posted May 19, 2006 The program probably crashed due to timeout issues.You're quite welcome.I don't really use AutoItX. I've liked to discover and use the Windows API functions directly to reduce overhead.Funny, I discovered AutioItX while learning about C# API functions and I was hoping that AutoItX would be easier and take less code, and that does seem to be the case but it doesn't give me as much control.I guess I'll just keep doing both. Link to comment Share on other sites More sharing options...
Toupix Posted October 13, 2006 Share Posted October 13, 2006 (edited) Hi,Yes, I'm using Visual Studio.Net 2005.The only thing that I had to change in your code to make it run and not crash my machine was:aix3c.WinWaitActive("Untitled -", "", 0);autoit.WinWaitActive("Untitled -", "", 1);I have the "unnecessary imports" because I'm making a C# project that uses all of the AutoItX commands, I just forgot to remove some of the code before posting.If you have any snippets of C# code using AutoItX I sure would appreciate it, I just want to make a C# example that usese all of AutoItX.Thanks for your help.I'm just doing a random (and uneducated) guess, but I had the same kind of issues when first trying the notepad hello script (with regular autoit, not in C#).I was terribly disapointed at my lack of common sense when I realised the timeout was due to the fact that my notepad was from a french windows, thus not showing "Untitled" in the title bar but the translation in my language, hence Autoit timing out when waiting for "Untitled" to show.Edit : Damnit sorry for digging an old post, I found this with search and didn't realized it was monthes old *bangs head on keyboard* Edited October 13, 2006 by Toupix 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