> In VS2005, I'd like to catch every keypress in every text editor
> window and possibly prevent the default VS Editor from ever knowing
[quoted text clipped - 3 lines]
> and from there I want to be notified of every keypress that is about
> to go to that document, with the ability to block it.
Hi.
You can use the following events to do what you want:
Events events = _applicationObject.Events;
// Must save _textDocumentKeyPressEvents globally, or GC will remove
it soon
TextDocumentKeyPressEvents _textDocumentKeyPressEvents =
((Events2)events).get_TextDocumentKeyPressEvents(null);
_textDocumentKeyPressEvents.BeforeKeyPress +=
_textDocumentKeyPressEvents_BeforeKeyPress;
_textDocumentKeyPressEvents.AfterKeyPress +=
_textDocumentKeyPressEvents_AfterKeyPress;
public void _textDocumentKeyPressEvents_BeforeKeyPress(string
Keypress, TextSelection Selection, bool InStatementCompletion, ref
bool CancelKeypress) {
if (Keypress[0] == ....) {
CancelKeypress = true;
}
}
Zachary Turner - 18 Jul 2007 19:08 GMT
On Jul 17, 10:00 am, sommar...@gmail.com wrote:
> Hi.
> You can use the following events to do what you want:
[quoted text clipped - 16 lines]
> CancelKeypress = true;
> }
Thanks for the response. I tried this and it doesn't catch certain
keys like escape, f1, f2, ... f12, pageup, pagedn, etc. Which is
unfortunate because I need to be able to catch pretty much every
single key on the keyboard. I coded around this by using a pinvoke to
SetWindowsHookEx, but it is pretty hairy and messy, I was hoping there
was a more elegant solution. :(