2

I need to catch keypresses in my C# program that has a WebBrowser control in it.

I know how to do it if there isn't any controls on the form or if I use a textbox or similar but the WebBrowser control seems to handle all keypresses itself.

Is there any way to override the WebBrowser_KeyDown function?

1
  • No I'm trying to make a program for taking screenshots of web pages. So I want to trigger the screenshot function when the user presses some key. Commented Feb 5, 2010 at 17:44

1 Answer 1

3

Set the KeyPreview property on the Form to True:

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.keypreview.aspx

Sign up to request clarification or add additional context in comments.

4 Comments

It didn't work when I used the WebBrowser control. Id did however work just fine when using a picture box.. Thanks anyway.
Strange your way does work if I remove focus from my program and give it focus again. But if I do it again (focus something else and then my program again) it stops working... Strange, but at least something to work on. Thanks!
I would say something other than your browser instance has focus.
There were a function called: webBrowser_PreviewKeyDown() that I didn't see before. That one seems to be able to catch key presses even when the web browser were out of focus.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.