Note: Advice in this article will only work for DotNetBrowser 1. See the corresponding article for DotNetBrowser 2 here.


C#

using DotNetBrowser.WinForms;
using System.Diagnostics;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private WinFormsBrowserView browserView;

        public Form1()
        {
            InitializeComponent();

            browserView = new WinFormsBrowserView();
            Controls.Add(browserView);

            browserView.Browser.LoadURL("http://google.com");
            browserView.KeyDown += OnBrowserKeyDown;
            browserView.KeyPress += OnBrowserKeyPress;
            browserView.KeyUp += OnBrowserKeyUp;

        }

        public void OnBrowserKeyDown(object sender, KeyEventArgs e)
        {
            Debug.WriteLine("Key down event captured: key code = " + e.KeyCode.ToString());
            if ((e.Alt))
            {
                Debug.WriteLine("Alt down event captured");
            }

            if ((e.KeyCode == Keys.P))
            {
                Debug.WriteLine("P down event captured");
            }

            if ((e.Alt & e.KeyCode == Keys.P))
            {
                Debug.WriteLine("Alt+P captured");
            }

        }

        public void OnBrowserKeyUp(object sender, KeyEventArgs e)
        {
            Debug.WriteLine("Key up event captured");
            if ((e.Alt & e.KeyCode == Keys.P))
            {
                Debug.WriteLine("Alt+P captured");
            }

        }

        public void OnBrowserKeyPress(object sender, KeyPressEventArgs e)
        {
            Debug.WriteLine("Key press event captured");
        }
    }
}

VB.NET

Imports DotNetBrowser
Imports DotNetBrowser.Events
Imports DotNetBrowser.WinForms

Public Class Form1
Private browserView As WinFormsBrowserView

Public Sub New()

InitializeComponent()

browserView = New WinFormsBrowserView()
Controls.Add(browserView)

browserView.Browser.LoadURL("http://google.com")
AddHandler browserView.KeyDown, AddressOf OnBrowserKeyDown
AddHandler browserView.KeyPress, AddressOf OnBrowserKeyPress
AddHandler browserView.KeyUp, AddressOf OnBrowserKeyUp

End Sub

Public Sub OnBrowserKeyDown(sender As Object, e As KeyEventArgs)
Debug.WriteLine("Key down event captured: key code = " + e.KeyCode.ToString())
If (e.Alt) Then
Debug.WriteLine("Alt down event captured")
End If

If (e.KeyCode = Keys.P) Then
Debug.WriteLine("P down event captured")
End If

If (e.Alt And e.KeyCode = Keys.P) Then
Debug.WriteLine("Alt+P captured")
End If

End Sub

Public Sub OnBrowserKeyUp(sender As Object, e As KeyEventArgs)
Debug.WriteLine("Key up event captured")
If (e.Alt And e.KeyCode = Keys.P) Then
Debug.WriteLine("Alt+P captured")
End If

End Sub

Public Sub OnBrowserKeyPress(sender As Object, e As KeyPressEventArgs)
Debug.WriteLine("Key press event captured")
End Sub

End Class