you can set a keyboard messages hook to your webbrowser control and filter out keyup keys messages or do some handling for them. Please see if code below would work for you:
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, IntPtr windowTitle);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll")]
public static extern int GetCurrentThreadId();
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
public const int WH_KEYBOARD = 2;
public static int hHook = 0;
// keyboard messages handling procedure
public static int KeyboardHookProcedure(int nCode, IntPtr wParam, IntPtr lParam)
{
Keys keyPressed = (Keys)wParam.ToInt32();
Console.WriteLine(keyPressed);
if (keyPressed.Equals(Keys.Up) || keyPressed.Equals(Keys.Down))
{
Console.WriteLine(String.Format("{0} stop", keyPressed));
return -1;
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
// find explorer window
private IntPtr FindExplorerWindow()
{
IntPtr wnd = FindWindowEx(webBrowser1.Handle, IntPtr.Zero, "Shell Embedding", IntPtr.Zero);
if (wnd != IntPtr.Zero)
{
wnd = FindWindowEx(wnd, IntPtr.Zero, "Shell DocObject View", IntPtr.Zero);
if (wnd != IntPtr.Zero)
return FindWindowEx(wnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero);
}
return IntPtr.Zero;
}
...
// install hook
IntPtr wnd = FindExplorerWindow();
if (wnd != IntPtr.Zero)
{
// you can either subclass explorer window or install a hook
// for hooking you don't really need a window handle but can use it
// later to filter out messages going to this exact window
hHook = SetWindowsHookEx(WH_KEYBOARD, new HookProc(KeyboardHookProcedure),
(IntPtr)0, GetCurrentThreadId());
//....
}
...
hope this helps, regards