开发者

Create automation macro support within an application

I need to get an automation macro like thing within our desktop application. The desktop app will probably be in VB.NET or C#.net. The reason is t开发者_开发问答o enable the user to record and replay certain tasks that they'd like to automate. Something like macros within office apps and visual studio. The first thing that comes to my mind is VBA.

Is this the right approach or whether are there any other options available?

Any gotchas or things to look out for, if some body has already done it before.

Some helpful links to get me going.

Whatever little help is highly appreciated.

Thanks in Advance.

Samrat.

P.S. This is a quite generic question not belonging to any specific technology. If some of you think the tags are inappropriate or if it needs some more tags which I missed out, feel free to edit them :)


Are you thinking of macros that are just for "record-replay" of some consecutive actions? This might be pretty well doable if you use the Command pattern in your UI programming. Then every user action is described by an object (derived from an abstract Command class having a "execute()" method). Now recording and replaying is simply storing a list of command objects, serializing them and your macro is done. For replaying it you simply deserialize the data and execute the list of commands again.

Hope that helps!


VSTA (Visual Studio Tools for Applications) is the replacement for VBA. It hasn't caught on as much as VBA did with 3rd party vendors or even in MSFT's own products (the only one that currently has it is InfoPath). But it's far more modern than VBA, if that is a concern.

Check out VSTA main page, and in particular the video: Integrating VSTA to Enable Macro Recording.


Here are some articles about the topic from MSDN:

Implement a Microsoft Word-like Object Model for Your .NET Framework Application

StickOut: A Desktop Sticky Notes Application in the .NET Framework 2.0


Does it have to be built in your application? There are macro solutions on the Windows level (assuming that's your target OS)

  • AutoHotKey
  • AutoIt


You could use Powershell cmdlets.

Implement each action performed by your GUI as a cmdlet. Then the users can use Powershell to script. I believe this is the approach used by Exchange Server and SQL Server. Of course those are both aimed at sysadmin users


Since you're developing the app yourself, you should be able to use the Windows API directly to create (AND monitor) mouse/keyboard events.

Take a look at keybd_event, mouse_event and GetCursorPos. They're pretty easy to use properly (I find them more straight forward than using SendInput, but thats just my opinion).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜