views:

29

answers:

2

I would like to know if there is a programmatically hook into the visual studio editor, so that I can determine whether or not someone is typing in the editor.

Thanks!

A: 

There most definitely is. Stacks of plugins do the same thing (such as ViEmu, Resharper, etc). Go and read the documentation on extending the VS editor using MEF. There's lots of it out there, a simple Google query will yield you plenty of results.

OJ
+2  A: 

There are a number of ways to do this in Visual Studio. Here are a few different hooks available.

  • IOleCommandTarget: Key strokes in Visual Studio will eventually present themselves as commands and be routed through this chain
  • KeyProcessor: For straight WPF keyboard input you can creata MEF IKeyProcessorProvider component and let the created KeyProcessor handle the input
  • ITextBuffer::Changed: Listen directly to changes in the underlying buffer to interpret input.

Each of these is fairly complex and adding a full sample for them in an SO question is just not reasonable. But just typing their names into google should get you pointed in the correct direction.

Do note though that keyboard input in Visual Studio is a very complex process. It has to deal with windows messages, old style Visual Studio commands, WPF, MEF hooks, translating accelorators, etc ... It's very messy and trying to tackle all input at any one choke point is fraught with problems. I've done my best to document the current state of Visual Studio keyboard input while working on a plugin and you can find it here

It's hardly a complete understanding though.

JaredPar