VB6 WebBrowser Disable Enter Key for textbox/input element

Preventing the Enter or Return key from being pressed and processed by the webbrowser control in VB6 is not as straight forward as you may, at first glance think.

I personally needed to prevent the Enter key on a webbrowser to prevent form submission to the form that owned the textbox I wanted to disable Enter key for.

You might think it would be as simple as enter code within the input elements keypress or keydown event ie …

or something along those lines. But for some reason this does not work. I even ready of suggestions of setting the webbrowser parent forms KeyPreview to true, then trapping and cancelling the enter key there but that does not work either.

Disable Enter (or any) Key in Web Browser

First, set reference to the Microsoft HTML Object Library (menu Project > References)

At the top of the module create the following private variable:

Then in the input boxes onkeydown event enter …

Then in the WebBrowsers BeforeNavigate2 sub …