Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / July 2007

Tip: Looking for answers? Try searching our database.

Catch keypresses in editor window

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Zachary  Turner - 13 Jul 2007 22:51 GMT
In VS2005, I'd like to catch every keypress in every text editor
window and possibly prevent the default VS Editor from ever knowing
that the key was pressed at all.  Is something like this possible?
I'm kind of just learnign as I go.  So far I have a simple addin that
is able to detect whenever a new document is opened in a text editor,
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.
sommarlov@gmail.com - 17 Jul 2007 16:00 GMT
> 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.  :(

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.