Hi list,
I made changes to my copy of the vs2008.vbs script provided by GW. I
added the ability to start a selection in the editor with F8 and to end
it with Shift-F8. I have a few questions and would very much appreciate
your comments on what I did. I will not include the whole script here,
but only my additions.
In the top section of the script I added a reference to the running
instance of Visual Studio like this:
dim env : set env = getobject(,"VisualStudio.DTE.8.0")
My first problem is what would happen if more than 1 instance of Visual
Studio is active. Is it possible to refer to a specific instance with
the GetObject function?
Now I define the variables that should be available globally:
Dim registeredSelectKeys : Set registeredSelectKeys =
CreateObject("Scripting.Dictionary")
Set registeredSelectKeys.Item(1) =
Keyboard.RegisterHotKey("F8","StartSelect")
Set registeredSelectKeys.Item(2) =
Keyboard.RegisterHotKey("Shift-F8","EndSelect")
dim editPoint
I tried to add my F8 and Shift-F8 keys to the RegisteredKeys object in
the LoadFormDesigner sub routine in the original script, but it didn't
work. It seems that the keys are only hooked when the form designer gets
focus. I tried to do this with the editor, but couldn't figure out how
to do it. This is my second question? How can I hook the F8 and Shift-F8
keys only when the editor gets focus? With the way I do it now, the keys
remain hooked to the selection routines even when the editor is not in
focus and even when I Alt-Tab to another program, the keys are still
hooked. In my version the keys are also never unhooked.
Now my actual selection sub routines:
sub StartSelect()
dim selection : set selection = env.activeDocument.selection
set editPoint = selection.ActivePoint.CreateEditPoint
end sub
sub EndSelect
dim selection : set selection = env.activeDocument.selection
selection.MoveToPoint editPoint,True
set editPoint = Nothing
end sub
That's it. As you can see not very elegant, but works basically.
Any comments very welcome.
Charles Steyn