diff --git a/gui/window/window_windows.go b/gui/window/window_windows.go index 9ccef66..5daf26c 100644 --- a/gui/window/window_windows.go +++ b/gui/window/window_windows.go @@ -67,6 +67,7 @@ const ( wmDestroy = 0x0002 wmMove = 0x0003 wmSize = 0x0005 + wmSetFocus = 0x0007 wmClose = 0x0010 wmQuit = 0x0012 wmMoving = 0x0216 @@ -193,6 +194,7 @@ func newBackend(opt Options) (backend, string, string, error) { return nil, "", "", errors.New("window: WebView2 could not be created (is the Microsoft Edge WebView2 Runtime installed?)") } c.Resize() + c.Focus() // the window got WM_SETFOCUS before the control existed if s, err := c.GetSettings(); err == nil { _ = s.PutAreDevToolsEnabled(opt.Debug) _ = s.PutAreDefaultContextMenusEnabled(opt.Debug) @@ -220,6 +222,14 @@ func wndproc(hwnd, msg, wp, lp uintptr) uintptr { _ = b.chromium.NotifyParentWindowPositionChanged() } b.reportFrame() + case wmSetFocus: + // The keyboard focus belongs in the WebView2 control (its own + // child window): without this a page gets no keys after the + // start or after Alt-Tab until it is clicked. + if b.chromium != nil { + b.chromium.Focus() + } + return 0 case wmApp: b.runQueue() return 0