Sign in to follow this  
Followers 0
WTF

C# Sample

15 posts in this topic

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. :)

Share this post


Link to post
Share on other sites



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:");

}

}

}

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by WTF

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by WTF

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#15 ·  Posted (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 :lmao:

*bangs head on keyboard*

Edited by Toupix

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0