• After focusing Windows forms WebBrower's scrollbar, keyboard hot keys stop working

    From loopimo@loopimo@zoho.com to comp.programming on Thu Jun 18 19:34:29 2026
    From Newsgroup: comp.programming

    I have form with a WebBrowser component & a few buttons that can be activated via F1, F2, F3, F4 keys. Form's KeyPreview set to True.

    Here is the KeyUp event handler for the form:

    Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
    If e.KeyCode = Keys.F1 AndAlso e.Modifiers = Keys.None Then
    e.Handled = True
    DoSomething("+")
    End If

    If e.KeyCode = Keys.F2 AndAlso e.Modifiers = Keys.None Then
    e.Handled = True
    DoSomething("-")
    End If

    Here's the event handler for the WebBrowser component to allow user execute corresponding functions when WebBrowser is focused:

    ' Source - https://stackoverflow.com/q/79962792
    ' Posted by ALT user, modified by community. See post 'Timeline' for change history
    ' Retrieved 2026-06-18, License - CC BY-SA 4.0

    Private Sub wBrowser_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
    Handles wBrowser.DocumentCompleted
    With DirectCast(sender, WebBrowser)
    AddHandler .Document.Body.KeyUp, New HtmlElementEventHandler(AddressOf WebBrowser1_KeyUp)
    End With
    End Sub

    Private Sub WebBrowser1_KeyUp(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
    If e.KeyPressedCode = Keys.F1 AndAlso e.CtrlKeyPressed = False AndAlso e.ShiftKeyPressed = False AndAlso e.AltKeyPressed = False Then
    DoSomething("+")
    End If

    If e.KeyPressedCode = Keys.F2 AndAlso e.CtrlKeyPressed = False AndAlso e.ShiftKeyPressed = False AndAlso e.AltKeyPressed = False Then
    DoSomething("-")
    End If


    Even if my hot keys stops working after focusing WebBrowser's scrollbar buttons
    still can be activated via Alt + 1, Alt + 2 key combinations.


    --- Synchronet 3.22a-Linux NewsLink 1.2