开发者

Interacting with dialogs in VS2010 with the Macro Recorder (using Visual Studio Macro Recorder to enter keystrokes automatically)

In one of my other questions, I inquired about a shortcut to enable a particular feature in the VS2010 IDE. It looks like the only way to make it happen is through the Macro Recorder, which I have unfortunately never used (as it looks quite powerful!).

The straightforward way to make my macro would be to start the recorder with CTRL+SHIFT+R, then go to Debug -> Exceptions, check all of the boxes I want, click OK, and then stop the recorder. Unfortunately, all that I can see is that it opens the Exceptions window, and no more than that.

I figured that if the Macro Recorder doesn't record mouse events, then surely it must record keyboard events, but I was wrong about that, too. Upon editing my TemporaryMacro, I saw that the only thing it does is

DTE.ExecuteCommand("Debug.Exceptions")

What I really want to do is add a method that can enter keystrokes like DOWN, ALT+T, and ENTER.

I have googled like crazy, gone through MSDN, and checked here on SO. I am embarrassed to say that I have been unable to find any information about an object in DTE that allows me to send keystrokes! Hopefully, someone here will know how to do it!

This is the closest thing I've found to a document 开发者_StackOverflow社区regarding keystroke automation: http://msdn.microsoft.com/en-us/library/8h31zbch.aspx

Edit: I figured it out how to send keystrokes, but how can you send them to popup dialogs???

Here's the code I tried:

Public Module RecordingModule
    Sub TemporaryMacro()
        DTE.ExecuteCommand("Debug.Exceptions")
        System.Windows.Forms.SendKeys.SendWait("+{TAB}")
        System.Windows.Forms.SendKeys.SendWait("{DOWN}")
        System.Windows.Forms.SendKeys.SendWait("%T")
        System.Windows.Forms.SendKeys.SendWait("{ENTER}")
    End Sub
End Module

I couldn't get it to work, so I tried debugging, and that's when I realized what was happening -- SendWait doesn't get called until after the dialog is dismissed.

So does anyone know how to use the Macro Recorder to interact with popup dialogs via keyboard commands?


I don't think you can send keystrokes to the dialog box.

I would recommend that you take a look at AutoHotKey, from there you can define interactions with dialog boxes. It works outside of Visual Studio, so you will probably find many more uses for it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜