internal/ui: bug fix: reset key states when the window is not focused on macOS

Updates #2183
This commit is contained in:
Hajime Hoshi 2022-08-05 20:22:33 +09:00
parent e81c46a0d7
commit 7b6ce7dcba

View File

@ -36,6 +36,13 @@ func (i *Input) updateKeys(window *glfw.Window) {
i.keyPressed = map[C.CGKeyCode]bool{} 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. // 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. // There is an assumption that the key states never change during one tick.
// Without this assumption, some functions in inpututil would not work correctly. // Without this assumption, some functions in inpututil would not work correctly.