Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone,

I'm having trouble with the WebBroser control. I'm using it to display a webpage from our MES system. The application is used to integrate peripherals such as a scanner.

Currently we're supporting scanners through a COM port. We want to add support for USB scanners. USB scanners act like a keyboard in order to capture the data we must handle the KeyDown event in the HtmlDocument (it is alway's displayed).

I found some code in order to attach my event handler:
VB
Private Sub NewBrowser_DocumentComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles NewBrowser.DocumentCompleted

   Dim document As HtmlDocument = NewBrowser.Document
   AddHandler document.Body.KeyDown, New HtmlElementEventHandler(AddressOf USBscan_KeyPress)

End Sub

This works wonderfull, untill some Javascript code changes the contents of the web page. When this happens, the event handler is dropped and I don't receive the keyboard events.

Is there a way to change this behaviour? Can I use another event to keep my event handler attached?

Thanks in advance!


Kind regards,
Bob Stanneveld
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900