From 7b6ce7dcba2cc2846ef3bfab1ce3fb90c0bb5045 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 5 Aug 2022 20:22:33 +0900 Subject: [PATCH] internal/ui: bug fix: reset key states when the window is not focused on macOS Updates #2183 --- internal/ui/input_glfw_darwin.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/ui/input_glfw_darwin.go b/internal/ui/input_glfw_darwin.go index 23aa2057a..81305a9c3 100644 --- a/internal/ui/input_glfw_darwin.go +++ b/internal/ui/input_glfw_darwin.go @@ -36,6 +36,13 @@ func (i *Input) updateKeys(window *glfw.Window) { i.keyPressed = map[C.CGKeyCode]bool{} } + if window.GetAttrib(glfw.Focused) != glfw.True { + for _, cgKey := range uiKeyToCGKey { + i.keyPressed[C.CGKeyCode(cgKey)] = false + } + return + } + // Record the key states instead of calling CGEventSourceKeyState every time at IsKeyPressed. // There is an assumption that the key states never change during one tick. // Without this assumption, some functions in inpututil would not work correctly.